Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8278763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:07:00+00:00 2026-06-08T09:07:00+00:00

I reworked the code to my notification class. Its spitting an Null pointer Exception

  • 0

I reworked the code to my notification class. Its spitting an Null pointer Exception at me every time I go to run it. So once more here is the code:

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RemoteViews;

public class kickStart extends Activity {
NotificationManager nm;
Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Notification notification = new Notification();
    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.note);
    contentView.setImageViewResource(R.id.icon, R.drawable.ic_launcher);
    contentView.setTextViewText(R.id.title, "Custom notification");
    contentView.setTextViewText(R.id.text, "This is a custom layout");
    notification.contentView = contentView;
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.contentIntent = contentIntent;
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    int CUSTOM_VIEW_ID = 10;
    nm.notify(CUSTOM_VIEW_ID, notification);
}
}

Now for the question: Why am I getting NPE… And how do I fix it.

HERE IS THE LOGCAT

07-21 17:58:33.360: W/dalvikvm(6511): threadid=1: thread exiting with uncaught exception (group=0x40018560)
07-21 17:58:33.360: E/AndroidRuntime(6511): FATAL EXCEPTION: main
07-21 17:58:33.360: E/AndroidRuntime(6511): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.this/com.example.this.kickStart}: java.lang.NullPointerException
07-21 17:58:33.360: E/AndroidRuntime(6511):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at android.os.Looper.loop(Looper.java:130)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at android.app.ActivityThread.main(ActivityThread.java:3683)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at java.lang.reflect.Method.invokeNative(Native Method)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at java.lang.reflect.Method.invoke(Method.java:507)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at dalvik.system.NativeStart.main(Native Method)
07-21 17:58:33.360: E/AndroidRuntime(6511): Caused by: java.lang.NullPointerException
07-21 17:58:33.360: E/AndroidRuntime(6511):     at com.example.this.kickStart.onCreate(kickStart.java:29)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-21 17:58:33.360: E/AndroidRuntime(6511):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-21 17:58:33.360: E/AndroidRuntime(6511):     ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:07:01+00:00Added an answer on June 8, 2026 at 9:07 am

    You haven’t initialized nm:

    nm.notify(CUSTOM_VIEW_ID, notification);
    

    You should add:

    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    

    before trying to use nm. Hope that helps!

    From LogCat

    For future reference these two lines:

    Caused by: java.lang.NullPointerException
        at com.example.this.kickStart.onCreate(kickStart.java:29)
    

    Tell us that the NPE is on line 29 in kickStart.java, specifically kickStart.onCreate(). Using this information you should be able to find you NPEs faster than any of us, since we don’t have line numbers. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Reworked my code a bit and decided to throw out URLLoader in favor
This is my abstract class which must be derived each time I want to
I'm working on some MIPS code for my Computer Organizations class, and well I
I recently reworked one of my own libraries to try out separating interface from
class my_class { public int add_1(int a, int b) {return a + b;} public
i've just reworked my recursion detection algorithm in my pet project dump_r() https://github.com/leeoniya/dump_r.php detecting
UPDATE: I've reworked the question, to show progress I've made, and maybe make it
I'm trying to run the HelloTriangle example, from The OpenGL ES 2.0 Programming Guide
I have this code: PageList: function(url, index, classes){ this.url = url; this.index = index;
I am playing with class generation ( one class for a table - inheritance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.