Android.App.Application Cannot Be Instantiated Due to Nullpointerexception

android.app.Application cannot be instantiated due to NullPointerException

I did some more tests and lockon the problem in the anonymous inner class for Back button, since the error will appear whenever I clicked this before restarting the app. If I switch activities using the "go back" button on the phone, everything is fine.

I added one line in the inner class

EditEntry.this.finish();

It does solve the problem. I tried to test it more systematical this time. Let's say the code without the above line is A, and the code with this line is B. Scenario goes like follow

1.run A then A --> Error

2.run A then B --> Error

3.run B then A --> OK

4.run B then B --> OK

Therefore, I assume it is some kind of problem about the activity stack?

Cannot run app in Android Studio. NullPointerException

I think the error maybe come from the code below in you onCreate:

run = new MainActivity();
wordPick = new String[16];
wordPick = run.Fill(wordPick);

Are you sure you need to create an activity by new Activity()? It's a little strange and not recommended.

try to replace the three lines with :

wordPick = Fill(new String[16]);

Maybe this can help.

java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException at LoadedApk.makeApplication

Looked into the ICS source code - It seems like for whatever reason the Package Manager can't get your package info - it could just be an eclipse/ADT bug where eclipse holds some kind of lock on the file, but whatever it is, it doesn't seem like something that you could cause with your code. I would suggest running a clean, uninstalling the app from the emulator/device, or if those don't work, you might try a fresh eclipse workspace.

Another thing that might be an issue is if you're using a Library project - try unlinking the two, cleaning, and then linking them back up again - but thats it for my bag o' tricks :)

UPDATE: yorkw gives a better explanation for why this occurs and its resolution here: RuntimeException: Unable to instantiate application

FATAL EXCEPTION: main ava.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException

Problem is here:

GetYouTubeUserCommentsTask task = new GetYouTubeUserCommentsTask(null, viewCount);

First argument should not be null.

Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
return false;
}
});
GetYouTubeUserCommentsTask task = new GetYouTubeUserCommentsTask(handler , viewCount);

NullPointerException in Android app (Bundle?)

The lookup is failing for mCheatButton because you forgot to assign it an id in the landscape version of the activity_quiz.xml layout file.

When you then try to set a ClickListener on a null object that is where the NullPointerException is coming from.

Why do I get NullPointerException when trying to instantiate Mediaplayer? Android Kotlin

Often it is best to wait to use the activity as a context until later in the lifecycle when things have been set up (e.g. in onCreate) to avoid initialization order issues. For exampe:

class MainActivity : AppCompatActivity() {
private lateinit var soundGenerator : SoundGenerator

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//...
soundGenerator = SoundGenerator(this)
}
}

Alternately, sometimes you can use applicationContext instead of the current activity as an appropriate context.

Unable to Instantiate Service - Java.NullPointerException

Here

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

you are trying to get Service context before creation so move initialization of wifi instance inside onStartCommand or onCreate method of WifiPullService service :

@Override
public void onCreate() {
super.onCreate();
// initialize wifi instace here
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
//....your code here...
}


Related Topics



Leave a reply



Submit