Skip to content
Advertisement

Android Studio Null object Reference

Creating an question/answer test application that scores you based on how many attempts it took to get it right (i.e on the first attempt 5 points, 2nd attempt 4 points… and so on)

the questions are stored in a .DB file in asset folder and after testing the scoring logic I’m now trying to draw from the database.

this is the DatabaseOpener

this is the DatabaseAccessor

and the main question page that answers the question

error being

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.teambasedlearningapp, PID: 7433 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.teambasedlearningapp/com.example.teambasedlearningapp.GroupAnswering}: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()’ on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3268) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3488) 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:2049) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:216) at an

So I am asking what is causing this error and how do I solve it

Advertisement

Answer

It might seen you are calling questionGet() method to soon.

On this way questionGet() is called when an instance of the activity is created when the context is not created yet that’s why it throws ‘android.content.Context.getApplicationInfo() on a null object reference.’ because the context is null and it is required in:

Try calling this on creation, with:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement