VeeN
VeeN

Reputation: 499

Ionic android application crashes instantly

I am making this post today because I have a problem with my ionic application.
So here it is, the app builds perfectly on an emulator with android studio. However, right after the splash screen it crashes instantly. I have no idea why this is happening. After running the app in debug mode, I get this error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.julesbsz.shortnews, PID: 862
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.julesbsz.shortnews/com.julesbsz.shortnews.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
        at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.load(GoogleAuth.java:47)
        at com.getcapacitor.PluginHandle.load(PluginHandle.java:72)
        at com.getcapacitor.PluginHandle.<init>(PluginHandle.java:44)
        at com.getcapacitor.Bridge.registerPlugin(Bridge.java:476)
        at com.getcapacitor.Bridge.registerAllPlugins(Bridge.java:440)
        at com.getcapacitor.Bridge.<init>(Bridge.java:170)
        at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:83)
        at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:62)
        at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:48)
        at com.julesbsz.shortnews.MainActivity.onCreate(MainActivity.java:17)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'

I really don't see what the problem is. Also, if you need more information about something in particular, let me know. Thank you very much.

Upvotes: 1

Views: 1830

Answers (1)

Edward van Raak
Edward van Raak

Reputation: 4910

If you read the stacktrace you can see that the crash originates from

at com.julesbsz.shortnews.MainActivity.onCreate(MainActivity.java:17)

It then appears to fail at some authorization logic

at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.load(GoogleAuth.java:47)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference

You did not post your code so perhaps this is a good time to learn how to set breakpoints and debug?

https://developer.android.com/studio/debug#breakPoints

Upvotes: 1

Related Questions