zyzdev / flutter_street_view

10 stars 34 forks source link

[Android] java.lang.NullPointerException: Parameter specified as non-null is null: method zyz.flutter.plugin.flutter_google_street_view.FlutterGoogleStreetView.onStreetViewPanoramaChange, parameter location #31

Open hukusuke1007 opened 1 year ago

hukusuke1007 commented 1 year ago

The app crashes when setting a location where Street View does not exist.

flutter_google_street_view: ^3.1.4
D/AndroidRuntime(24825): Shutting down VM
E/AndroidRuntime(24825): FATAL EXCEPTION: main
E/AndroidRuntime(24825): Process: app.product.sekaiisanwalking.development, PID: 24825
E/AndroidRuntime(24825): com.google.maps.api.android.lib6.common.apiexception.f: java.lang.NullPointerException: Parameter specified as non-null is null: method zyz.flutter.plugin.flutter_google_street_view.FlutterGoogleStreetView.onStreetViewPanoramaChange, parameter location
E/AndroidRuntime(24825):    at com.google.maps.api.android.lib6.streetview.camera.i.g(:com.google.android.gms.dynamite_mapsdynamite@233013044@23.30.13 (190400-0):323)
E/AndroidRuntime(24825):    at com.google.maps.api.android.lib6.streetview.camera.e.run(:com.google.android.gms.dynamite_mapsdynamite@233013044@23.30.13 (190400-0):3)
E/AndroidRuntime(24825):    at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime(24825):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(24825):    at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(24825):    at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(24825):    at android.app.ActivityThread.main(ActivityThread.java:7918)
E/AndroidRuntime(24825):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(24825):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(24825):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
E/AndroidRuntime(24825): Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method zyz.flutter.plugin.flutter_google_street_view.FlutterGoogleStreetView.onStreetViewPanoramaChange, parameter location
E/AndroidRuntime(24825):    at zyz.flutter.plugin.flutter_google_street_view.FlutterGoogleStreetView.onStreetViewPanoramaChange(Unknown Source:2)
E/AndroidRuntime(24825):    at com.google.android.gms.maps.zzai.zzb(com.google.android.gms:play-services-maps@@18.1.0:1)
E/AndroidRuntime(24825):    at com.google.android.gms.maps.internal.zzbl.zza(com.google.android.gms:play-services-maps@@18.1.0:3)
E/AndroidRuntime(24825):    at com.google.android.gms.internal.maps.zzb.onTransact(com.google.android.gms:play-services-maps@@18.1.0:3)
E/AndroidRuntime(24825):    at android.os.Binder.transact(Binder.java:1164)
E/AndroidRuntime(24825):    at m.fh.c(:com.google.android.gms.dynamite_mapsdynamite@233013044@23.30.13 (190400-0):8)
E/AndroidRuntime(24825):    at com.google.maps.api.android.lib6.streetview.camera.i.g(:com.google.android.gms.dynamite_mapsdynamite@233013044@23.30.13 (190400-0):316)
E/AndroidRuntime(24825):    ... 9 more
W/ing.development(24825): Accessing hidden field Landroid/os/Message;->next:Landroid/os/Message; (unsupported, reflection, allowed)
BalaSundar009 commented 1 year ago

same here..

foxide123 commented 1 year ago

Same. Tried to run the example application but get this error. Overriding onStreetViewPanoramaChange and catching the exception doesn't help.

liorboyango commented 1 year ago

That's an sdk issue, see here: https://issuetracker.google.com/issues/222232904

And BTW, if you set initPanoId instead of initPos it won't crash - not very useful but perhaps it might help someone

liorboyango commented 1 year ago

I made a fork with a fix, hope it helps:

  flutter_google_street_view:
    git:
      url: https://github.com/liorboyango/flutter_street_view.git
      path: flutter_google_street_view
      ref: master
yishaiSilver commented 10 months ago

I am also having this issue. Adding the above to my pubspec.yaml gives the following issue. Any help would be appreciated:


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_google_street_view:compileDebugJavaWithJavac'.
> error: invalid source release: 17

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s```
Nicoeevee commented 10 months ago

I am also having this issue. Adding the above to my pubspec.yaml gives the following issue. Any help would be appreciated:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_google_street_view:compileDebugJavaWithJavac'.
> error: invalid source release: 17

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s```

Same issue here when build with Codemagic

lazytesting commented 7 months ago

@liorboyango would it be possible to merge your fork and publish a new release to pub.dev?

liorboyango commented 5 months ago

I am also having this issue. Adding the above to my pubspec.yaml gives the following issue. Any help would be appreciated:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_google_street_view:compileDebugJavaWithJavac'.
> error: invalid source release: 17

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s```

Set your Android env to use Java17

liorboyango commented 3 months ago

See solution here: https://github.com/zyzdev/flutter_street_view/issues/39

yogeshButani commented 1 month ago

That's an sdk issue, see here: https://issuetracker.google.com/issues/222232904

And BTW, if you set initPanoId instead of initPos it won't crash - not very useful but perhaps it might help someone

@liorboyango Still app is crashing, please tell the solution for this, i used initPanoId instead of pass lat longs, and app crashes.

class StreetViewPanoramaInitDemo extends StatefulWidget { const StreetViewPanoramaInitDemo({super.key});

@override State createState() => _StreetViewPanoramaInitDemoState(); }

class _StreetViewPanoramaInitDemoState extends State { double lat = 22.668861; double long = 75.815119;

@override void initState() { super.initState(); Future.delayed(Duration.zero, () { checkStreetView(lat, long); // checkEnableApis(); }); }

String initPanoId = '';

checkEnableApis(){ checkStaticStreetView(apiKey: APIservices.googleKey,lat: lat.toString(),long: long.toString()); checkDynamicStreetView(apiKey: APIservices.googleKey,lat: lat.toString(),long: long.toString()); }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Street View Init Demo'), leading: IconButton( icon: const Icon(Icons.arrow_back), onPressed: () => Navigator.pop(context), ), ), body: SafeArea( child: Stack( children: [ FlutterGoogleStreetView( userNavigationEnabled: false, // initPos: LatLng(lat, long), initPanoId: initPanoId, initSource: StreetViewSource.def, initBearing: 30, streetNamesEnabled: false, zoomGesturesEnabled: true, onStreetViewCreated: (StreetViewController controller) async { debugPrint('Street View Created >>>'); }, ), ], ), ), ); }

Future checkStreetView(double latitude, double longitude) async { String apiKey = APIservices.googleKey;

// Check Street View at the requested location
final uri =
    Uri.https('maps.googleapis.com', 'maps/api/streetview/metadata', {
  'key': apiKey,
  'location': '$latitude,$longitude',
});

final response = await http.get(uri);

if (response.statusCode == 200) {
  final data = jsonDecode(response.body);
  final success = data['status'] == 'OK';

  if (success) {
    log('Success >>> ${data.toString()}');
    debugPrint('Street View is available for this location.');
    // Use the exact lat/long
    lat = latitude;
    long = longitude;
    initPanoId = data['pano_id'].toString();
    setState(() {});
  } else {
    debugPrint('Street View not available at this location.');
    // Find the nearest Street View within a search range
    await _findNearbyStreetView(
        latitude, longitude, 100); // Start with 100 meters
  }
} else {
  debugPrint(
      'Failed to fetch Street View metadata. Status code: ${response.statusCode}');
}

}

Future _findNearbyStreetView( double latitude, double longitude, int searchRadius) async { String apiKey = APIservices.googleKey;

// Define an expanding search radius (increment by 100 meters per iteration)
int maxRadius = 5000; // You can set a max range limit (5 km in this case)

for (int radius = searchRadius; radius <= maxRadius; radius += 100) {
  debugPrint('Searching for Street View within $radius meters...');

  // Define the Street View metadata API with location and radius
  final streetViewUri =
      Uri.https('maps.googleapis.com', 'maps/api/streetview/metadata', {
    'key': apiKey,
    'location': '$latitude,$longitude',
    'radius': radius.toString(), // Expand search with radius
  });

  final streetViewResponse = await http.get(streetViewUri);

  if (streetViewResponse.statusCode == 200) {
    final streetViewData = jsonDecode(streetViewResponse.body);
    if (streetViewData['status'] == 'OK') {
      // Found a nearby Street View
      final foundLat = streetViewData['location']['lat'];
      final foundLng = streetViewData['location']['lng'];
      final paranomaId = streetViewData['pano_id'];
      log('Nearby Street View found >>> ${streetViewData.toString()}');
      debugPrint(
          'Street View available at nearby location: ($foundLat, $foundLng)');
      lat = double.parse(foundLat.toString());
      long = double.parse(foundLng.toString());
      initPanoId = paranomaId;
      debugPrint('initPanoId>>>> $initPanoId');
      setState(() {});
      break;
    } else {
      debugPrint(
          'No Street View found within $radius meters. Expanding search...');
    }
  }
}

}

Future checkStaticStreetView( {required String apiKey, required String lat, required String long}) async { final uri = Uri.https('maps.googleapis.com', 'maps/api/streetview', { 'key': apiKey, 'location': '$lat,$long', 'size': '400x400', });

final response = await http.get(uri);

if (response.statusCode == 200) {
  print('Static Street View is enabled.------');
} else {
  print(
      'Static Street View is not enabled. Status Code: ${response.statusCode}');
}

}

Future checkDynamicStreetView( {required String apiKey, required String lat, required String long}) async { final uri = Uri.https('maps.googleapis.com', 'maps/api/streetview/metadata', { 'key': apiKey, 'location': '$lat,$long', // Example lat, long (Statue of Liberty) });

final response = await http.get(uri);

if (response.statusCode == 200) {
  final data = jsonDecode(response.body);
  debugPrint('data>>>${data.toString()}');
  if (data['status'] == 'OK') {
    print('Dynamic Street View is enabled.------');
  } else {
    print(
        'Dynamic Street View is not available for this location, but API might still be enabled.');
  }
} else {
  print(
      'Dynamic Street View is not enabled. Status Code: ${response.statusCode}');
}

} }

yogi1610 commented 1 month ago

@liorboyango @lazytesting @Nicoeevee @yishaiSilver @BalaSundar009 @hukusuke1007

Does somebody find the solution for this? Apps keep crashing with the package flutter_google_street_view: ^3.1.4, giving error in console com.google.maps.api.android.lib6.common.apiexception.f: java.lang.NullPointerException: Parameter specified as non-null is null: method zyz.flutter.plugin.flutter_google_street_view.FlutterGoogleStreetView.onStreetViewPanoramaChange, parameter location

What is the solution for this? because there is not any update on package since 14 months, what to do next? Please reply