Null object reference android studio

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

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.teambasedlearningapp, PID: 7433 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo: 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

Источник

Google Android — это несложно

Добро пожаловать на форум сайта

Ошибка on a null object reference

Ошибка on a null object reference

Сообщение Батька Андройд » 28 авг 2015, 11:11

Re: Ошибка on a null object reference

Сообщение An-droid » 28 авг 2015, 11:24

Re: Ошибка on a null object reference

Сообщение Батька Андройд » 28 авг 2015, 11:43

Re: Ошибка on a null object reference

Сообщение An-droid » 28 авг 2015, 11:44

Re: Ошибка on a null object reference

Сообщение Батька Андройд » 28 авг 2015, 11:52

Проблемная переменная ratioRadius

Re: Ошибка on a null object reference

Сообщение An-droid » 28 авг 2015, 12:06

Тут либо проблема с тем, что не отправляется контекст, и тогда в строке
pathView = new PathView(this); нужно вместо this написать getApplicationContext()

либо где то переменная используется, например при построении фигуры shape = new Shape() и тогда
нужно инициализировать ratioRadius сразу в конструкторе, при создании объекта, тем более что значение уже известно.
вместо

Источник

Null Object Reference in Android Application

So I am trying to get this below portion of the code for a shopping list application to run, however i am getting an error that is causing the application to crash.

When the application run, a fatal error occurs at line 61 which is at the for loop » for (Map.Entry entry : map1.entrySet())»

I am getting the below error from Android Studio IDE

E/AndroidRuntime: FATAL EXCEPTION: main Process: example.com.shoppinghelper, PID: 17150 java.lang.NullPointerException: Attempt to invoke interface method ‘java.util.Set java.util.Map.entrySet()’ on a null object reference at example.com.shoppinghelper.shopping_container.ProductContainer.lambda$null$0$ProductContainer(ProductContainer.java:61) at example.com.shoppinghelper.shopping_container.ProductContainer$$Lambda$6.onComplete(Unknown Source:0) at com.google.android.gms.tasks.zzf.run(Unknown Source:23) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6940) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Basically, the code is trying to data to a notifications collection provided the certain list was shared by someone. However, if if there is no one i shared the particular shopping list with, then i am getting the above stated error.

Источник

Getting Null Object Reference when Trying to Access Dynamic Data — Android Studio [duplicate]

I’m using it to decrypt a password (said password is in a URI is in another class). If I hardcode the key, it works. I’m trying a dynamic approach, and this is where I struggle due to my lack of experience. I’m not able to get the two classes to work together.

Any suggestions on how to get these classes working together?

1 Answer 1

What you’ve got is an IllegalArgumentException thrown by the SecretKeySpec constructor, specifically in this line:

A bit of digging around in the documentation reveals that this exception is thrown

«if algorithm is null or key is null or empty«.

In Java, String md5key = «»; is an empty String, thus throwing this exception when passed to the SecretKeySpec Constructor. In order to solve it, initialise your SecretKeySpec after md5key has a proper value. More specifically, change that line to:

and add this line where Log.i(«Test: «, md5key); is:

Before calling encryppass() in this line:

You’ll need to run myMethod() , in order to obtain the md5key value from the xml file. Simply add, before the line mentioned above, the follwing:

In this case, this is referring to MainActivity, and is the Context .

The following are a few more trivial mistakes (they won’t cause any errors, but aren’t really in good practice either — or are redundant):

There is no need for a second switch with the exact same condition. Just add a second case to the original switch:

Источник

Google Android — это несложно

Добро пожаловать на форум сайта

Ошибка on a null object reference

Ошибка on a null object reference

Сообщение Батька Андройд » 28 авг 2015, 11:11

Re: Ошибка on a null object reference

Сообщение An-droid » 28 авг 2015, 11:24

Re: Ошибка on a null object reference

Сообщение Батька Андройд » 28 авг 2015, 11:43

Re: Ошибка on a null object reference

Сообщение An-droid » 28 авг 2015, 11:44

Re: Ошибка on a null object reference

Сообщение Батька Андройд » 28 авг 2015, 11:52

Проблемная переменная ratioRadius

Re: Ошибка on a null object reference

Сообщение An-droid » 28 авг 2015, 12:06

Тут либо проблема с тем, что не отправляется контекст, и тогда в строке
pathView = new PathView(this); нужно вместо this написать getApplicationContext()

либо где то переменная используется, например при построении фигуры shape = new Shape() и тогда
нужно инициализировать ratioRadius сразу в конструкторе, при создании объекта, тем более что значение уже известно.
вместо

Источник

Читайте также:  Патч безопасности android июнь 2021
Оцените статью