Skip to content Skip to sidebar Skip to footer

Nullpointerexception On Starting Application

I tired to start my Activity (declared in AndroidManifest) , but then I saw that error(s) : 08-11 16:04:05.952: E/AndroidRuntime(815): FATAL EXCEPTION: main 08-11 16:04:05.952: E/A

Solution 1:

I would venture to guess that you are initializing pm outside of onCreate(). This would try initializing it before you actually had a Context and it would return null. You need to do this inside of onCreate() and before calling the function that uses it.

PackageManager pm;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    pm = getPackageManager();

    /* Some code has been removed */if(dcm.isAdminActive(c))
    ustawWidokMain();

Anything that needs a Context inside of an Activity needs to be initialized, at the earliest, in onCreate() since the Activity and its Context aren't initialized before this.

Solution 2:

Have you declared permissions in Manifest?

<uses-permissionandroid:name="android.permission.CAMERA" /><uses-featureandroid:name="android.hardware.camera" /><uses-featureandroid:name="android.hardware.camera.autofocus" />

And what is pm? Where do you have instatiate it? Seems you are missing to.

Solution 3:

It means you did not declare or initialize the object in this ustawWidokMain method. Please recheck or debug to which line gives you error.

Post a Comment for "Nullpointerexception On Starting Application"