-1

I have doubt on String literal uninitialised variable html. Running version and trace are matching line number 95 is comment.

public class WebviewActivity extends AppCompatActivity {

String html;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 }
@Override
protected void onResume() {
    super.onResume();
    generateChart();
}
private void generateChart(){ 

    html = "<!DOCTYPE html>";
    html += "<head>";
    ...
}

}

Not able to understand fully this crash. A method is in defined in NDK lib generateChart and in webview activity also with same name but different signatures. Native method is called in webview through ndk wrapper. I am confused with crash line Method.Invoke(Native method) Is this crash due to native method or Java method? And how to simulate this error to debug.

java.lang.RuntimeException:
  at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4330)
  at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:4362)
  at android.app.servertransaction.ResumeActivityItem.execute (ResumeActivityItem.java:52)
  at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:176)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:97)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2128)
  at android.os.Handler.dispatchMessage (Handler.java:107)
  at android.os.Looper.loop (Looper.java:214)
  at android.app.ActivityThread.main (ActivityThread.java:7711)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:516)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950)
Caused by: java.lang.NullPointerException:
  at in.multinetsystems.vedicastro.util.WebviewActivity.generateChart (WebviewActivity.java:95)
  at in.multinetsystems.vedicastro.util.WebviewActivity.onResume (WebviewActivity.java:37)
  at android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1567)
  at android.app.Activity.performResume (Activity.java:7989)
  at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4320)
  at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:4362)
  at android.app.servertransaction.ResumeActivityItem.execute (ResumeActivityItem.java:52)
  at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:176)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:97)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2128)
  at android.os.Handler.dispatchMessage (Handler.java:107)
  at android.os.Looper.loop (Looper.java:214)
  at android.app.ActivityThread.main (ActivityThread.java:7711)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:516)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950)

Thanks

DK Manchanda
  • 1
  • 1
  • 2
  • Do you understand that line 95 in file `WebviewActivity.java` is throwing `NullPointerException`? That line is in method `generateChart`. – Abra Jun 03 '21 at 04:08
  • Actually these line numbers are comments. In android studio. I think trace line numbers are not matching with actual file. – DK Manchanda Jun 03 '21 at 04:13
  • 1
    The only way the line numbers can't match is if you've changed your source code after compiling. Duplicate. – user207421 Jun 03 '21 at 04:31
  • *"I am confused with crash line Method.Invoke(Native method) Is this crash due to native method or Java method?"* - It is highly unlikely. *"And how to simulate this error to debug."* - Sorry, we can't help you with that. – Stephen C Jun 03 '21 at 05:34
  • The only possible explanation I can think of for an NPE involving the `html` variable in `generateChart()` is that there is *another thread* updating `html` while this thread is trying to do that. If that was the problem, then it *could* be difficult to reproduce. (However, this theory is based on the limited code + other information you have shown us, and the problem would have to be in code that you **haven't** shown us.) – Stephen C Jun 03 '21 at 05:39
  • yes.generateChart() method is also in multiple buttons refresh(), pickerDone etc and generateChart method goes to ndk native C lib for large html page processing. Will setting String html=""; solve the issue? or i need to reduce processing time of webpage loading. – DK Manchanda Jun 03 '21 at 06:04
  • Thanks for attempt to help. @Stephen C: You were right, problem was there in the other code not shared. To share with all of you:Indeed issue was in generateChart but line number was not 95 as per Stack trace. This function is sending array of String to NDK C++ Core Wrapper JNI. And JNI was receiving NULL and was causing NPE. Reason for not reproducing was it was impacting only API 29 and Android10. I found when I used one Redme 4a and crashed. And it give hint of Timezone.Default ID not matching with knowntimezones and sending Null to JNI string – DK Manchanda Jun 05 '21 at 03:43

1 Answers1

1

In general, when looking at a stacktrace, look for the last "Caused by", then look at the "at" lines below for the first line that mentions your code.

In this case, that is:

Caused by: java.lang.NullPointerException:
  at in.multinetsystems.vedicastro.util.WebviewActivity.generateChart (WebviewActivity.java:95)

That shows that the code in line 95 of WebviewActivity.java, in the method generateChart, is causing a NullPointerException.

Now you just need to look at that line and figure out which reference value can be null, but is used anyway, then backtrack the code to figure out why it is null and why you didn't check for that.

Andreas
  • 154,647
  • 11
  • 152
  • 247
  • Actually this line number 95 is comment in file, in android studio. I think trace line numbers are not matching with actual file – DK Manchanda Jun 03 '21 at 04:25
  • 2
    @DKManchanda Then the running code is not from that source file, but from an earlier (or later) version of the source code. – Andreas Jun 03 '21 at 04:28
  • And I'm not able to reproduce this crash on simultor or device. I tried switching to home back to resume etc. On my devices its working fine. – DK Manchanda Jun 03 '21 at 04:34
  • 1
    Well ... there's not much we can do to help you. You've got an error you can't reproduce, source code that doesn't match the stacktrace ... and you haven't shared any source code. I think it is on you to figure out the mess. I suggest starting with finding the right source code for the stacktrace in your version control ... and fixing your "processes" so that can always tie the bug reports to a specific version of your source code. – Stephen C Jun 03 '21 at 04:39
  • 1
    @DKManchanda Perhaps the fact that the running code doesn't match the source code, and that you cannot reproduce the problem with the source code you have, means that the source code is different because the problem has **already been fixed**. – Andreas Jun 03 '21 at 05:25
  • code posted. Version control is in order. – DK Manchanda Jun 03 '21 at 05:26