DJI-Mobile-SDK-Tutorials / Android-GSDemo-GoogleMap

A Demo for using DJI Mobile SDK to create a Waypoint Mission App using Google Map.
MIT License
28 stars 55 forks source link

getFlightController returns null always, when working with simulator as explained in the demo #15

Open Dhana-Krishnasamy opened 6 years ago

Dhana-Krishnasamy commented 6 years ago

I'm following this sample: https://developer.dji.com/mobile-sdk/documentation/android-tutorials/GSDemo-Google-Map.html

However I see getFlightController is returning null, while mobile is connected to the controller and simulator is running, drone is connected to the mac.

Problem line: https://github.com/DJI-Mobile-SDK-Tutorials/Android-GSDemo-GoogleMap/blob/684f224cb3aa73317703c7dffffc2dd90b5a4366/GSDemo/app/src/main/java/com/dji/GSDemo/GoogleMap/MainActivity.java#L210

vkkeeper commented 3 years ago

Just a workaround (yes, this is dirty hack, and I know, this is obviously, but may help someone to save time a bit).

                   FlightController flightController = null;
                    for (int i=0; i<3; i++) {
                        //TODO: SDK bug? https://github.com/DJI-Mobile-SDK-Tutorials/Android-GSDemo-GoogleMap/issues/15
                        flightController = ((Aircraft) product).getFlightController();
                        if (flightController!=null)
                            break;
                        else {
                            try {
                                Thread.sleep(300);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    if (flightController==null)
                        throw new Error("Cannot get flightController");

I'm sorry. After a month of getting this error, I can say, that this is not a solution at all. If you didn't get a FlightController at a first call, you, probably, never get it. Sorry again.