Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException sometimes after download starting #117

Open
s681562 opened this issue Mar 13, 2024 · 0 comments
Open

NullPointerException sometimes after download starting #117

s681562 opened this issue Mar 13, 2024 · 0 comments

Comments

@s681562
Copy link

s681562 commented Mar 13, 2024

D/FLUTTER OTA(14386): STREAM OPENED
D/FLUTTER OTA(14386): REQUEST PERMISSIONS RESULT RECEIVED
D/FLUTTER OTA(14386): DOWNLOAD STARTING
E/AndroidRuntime(14386): FATAL EXCEPTION: main
E/AndroidRuntime(14386): Process: kr.co.klcns.mrs_app, PID: 14386
E/AndroidRuntime(14386): java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {kr.co.klcns.mrs_app/kr.co.klcns.mrs_app.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime(14386): at android.app.ActivityThread.deliverResults(ActivityThread.java:5864)
E/AndroidRuntime(14386): at android.app.ActivityThread.handleSendResult(ActivityThread.java:5903)
E/AndroidRuntime(14386): at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
E/AndroidRuntime(14386): at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
E/AndroidRuntime(14386): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(14386): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(14386): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)
E/AndroidRuntime(14386): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(14386): at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(14386): at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(14386): at android.app.ActivityThread.main(ActivityThread.java:8663)
E/AndroidRuntime(14386): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(14386): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/AndroidRuntime(14386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/AndroidRuntime(14386): Caused by: java.lang.NullPointerException
E/AndroidRuntime(14386): at k1.a.b(Unknown Source:38)
E/AndroidRuntime(14386): at io.flutter.embedding.engine.c$c.h(Unknown Source:20)
E/AndroidRuntime(14386): at io.flutter.embedding.engine.c.b(Unknown Source:14)
E/AndroidRuntime(14386): at io.flutter.embedding.android.d.y(Unknown Source:59)
E/AndroidRuntime(14386): at io.flutter.embedding.android.c.onRequestPermissionsResult(Unknown Source:10)
E/AndroidRuntime(14386): at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8833)
E/AndroidRuntime(14386): at android.app.Activity.dispatchActivityResult(Activity.java:8663)
E/AndroidRuntime(14386): at android.app.ActivityThread.deliverResults(ActivityThread.java:5857)
E/AndroidRuntime(14386): ... 13 more

Here my snippet:

`
void _onVersionUpdate(VersionUpdate event, Emitter emit) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String protocol = prefs.containsKey('protocol') ? prefs.getString('protocol')! : "https";
String host = prefs.containsKey('host') ? prefs.getString('host')! : "0.0.0.0";
int port = prefs.containsKey('port') ? prefs.getInt('port')! : 0;
String jwt = prefs.containsKey('token') ? prefs.getString('token')! : "";
PackageInfo packageInfo = await PackageInfo.fromPlatform();

try {
OtaUpdateVersion otaUpdateVersion = await HttpClientService().getVersion(protocol, host, port, jwt, packageInfo.version);
String path = otaUpdateVersion.path;
final String url = sprintf("%s://%s:%s/%s", [protocol, host, port, path]);

OtaUpdate().execute(url, headers: {'Accept': 'application/octet-stream'},).listen(
  (OtaEvent event) async {
    switch (event.status) {
      case OtaStatus.CANCELED:
        break;
      case OtaStatus.ALREADY_RUNNING_ERROR:
        break;
      case OtaStatus.CHECKSUM_ERROR:
        break;
      case OtaStatus.PERMISSION_NOT_GRANTED_ERROR:
        break;
      case OtaStatus.DOWNLOAD_ERROR:
        break;
      case OtaStatus.INTERNAL_ERROR:
        break;
      case OtaStatus.DOWNLOADING:
        try {
          try {
            add(LoginPageUpdateChanged(event: event, version: otaUpdateVersion.version));
          } on StateError catch (e) {
            FileLogger.write('Failed to make OTA update. Details: $e');
          }
        } on StateError catch (e) {
          FileLogger.write('Failed to make OTA update. Details: $e');
        }
        break;
      case OtaStatus.INSTALLING:
        try {
          add(LoginPageInitEvent());
        } on StateError catch (e) {
          FileLogger.write('Failed to make OTA update. Details: $e');
        }
        FileLogger.write("tryOtaUpdate: $event");
        break;
    }
  },
);

} catch (e) {
FileLogger.write('Failed to make OTA update. Details: $e');
}
}

`

How to catch this error? Sometimes unexpected happen. Any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant