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 6745137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:10:06+00:00 2026-05-26T12:10:06+00:00

While programming a countdown script into the status bar but I still keep forced

  • 0

While programming a countdown script into the status bar but I still keep forced closes when i call the
function OnClickListener destroy to kill the application).
I think something is wrong with the ‘myNotificationManager.cancel(1);’ but I can’t figure out whats the mistake.

Here is my code

public class ZaagmanActivity extends Activity {
public Handler handler = new Handler();
public NotificationManager myNotificationManager;
 private static final int NOTIFICATION_ID = 1;
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button button = (Button)findViewById(R.id.refresh);
    button.setOnClickListener(refresh);
    Button button1 = (Button)findViewById(R.id.destroy);
    button1.setOnClickListener(destroy);
    Button button2 = (Button)findViewById(R.id.counter);
    button2.setOnClickListener(counter);
    //test


}
private void GeneratNotification(){

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

      CharSequence NotificationTicket = "Counter gestart";
      CharSequence NotificationTitle = "Zaagmans Counter";
      CharSequence NotificationContent = Nextwedsmall();
      long when = System.currentTimeMillis();

      Notification notification = new Notification(R.drawable.poppetje,NotificationTicket, when);
      Context context = getApplicationContext();
      Intent notificationIntent = new Intent(this,ZaagmanActivity.class);
      PendingIntent contentIntent =
      PendingIntent.getActivity(this, 0, notificationIntent, 0);

      notification.setLatestEventInfo(context, NotificationTitle,
        NotificationContent, contentIntent);

      myNotificationManager.notify(NOTIFICATION_ID, notification);

    }

private OnClickListener destroy = new OnClickListener() {
    public void onClick(View v) {
    System.out.println("Closing");
    myNotificationManager.cancel(1);
    handler.removeCallbacks(notification);
    finish();
              }
}; 

private OnClickListener counter = new OnClickListener() {
    public void onClick(View v) {
        notification.run();
              }
}; 

private OnClickListener refresh = new OnClickListener() {
    public void onClick(View v) {
      refresh();

      Button button1 = (Button)findViewById(R.id.destroy);
      button1.setOnClickListener(destroy);

     ; 
    }
}; 




private final Runnable showtext = new Runnable()  {


    public void run()  {

        TextView t=new TextView(getApplicationContext()); 
        t=(TextView)findViewById(R.id.t);
        t.setText(Nextwed());
        handler.postDelayed(this, 500);
    }
};

private final Runnable notification = new Runnable()  {


    public void run()  {
        GeneratNotification();
        handler.postDelayed(this, 500);
    }
};  



public Calendar Nextwednesday(int dow){
     Calendar date = Calendar.getInstance();
     int diff = dow - date.get(Calendar.DAY_OF_WEEK);
     if (!(diff > 0)) {
         diff += 7;
     }
     date.add(Calendar.DAY_OF_MONTH, diff);
     date.set(Calendar.HOUR_OF_DAY, 12);
     System.out.println(date);
     return date;
} public String Nextwedsmall() {
    //

    long wednes = Nextwednesday(Calendar.WEDNESDAY).getTimeInMillis();
    System.out.println(wednes);

    Date date = new Date();   // given date
    Calendar date2 = GregorianCalendar.getInstance(); // creates a new calendar instance
    date2.setTime(date); 
    long now = date2.getTimeInMillis();

    long zaagmans = wednes - now;

    System.out.println("time "+date2.getTime());
    long Hour = date2.get(Calendar.HOUR_OF_DAY);
    Hour = Hour -2;
    long Minute = date2.get(Calendar.MINUTE);
    long Seconds = date2.get(Calendar.SECOND);
    long mSeconds = date2.get(Calendar.MILLISECOND);
    float total = (mSeconds + (1000*Seconds) + (60*1000 * Minute) + (60*60*1000 * Hour));

    zaagmans = (long) (zaagmans - total + (11*60*60*1000));
    long days  = zaagmans / (1000*60*60*24);
    long hours = zaagmans / (1000*60*60) ;
    long mins  = zaagmans / (1000*60) ;
    long  secs  =  zaagmans / 1000 ;
    long dd = days;
    long  hh = hours - days  * 24;
    long  mm = mins  - hours * 60;
    long  ss = secs  - mins  * 60;
    System.out.println(date2);
    date2.clear();
    return (dd+" dag(en), "+hh+" uur(en), "+mm+" minuten en "+ss+" seconden");
}
public String Nextwed() {
    //

    long wednes = Nextwednesday(Calendar.WEDNESDAY).getTimeInMillis();
    System.out.println(wednes);
    Date date = new Date();   // given date
    Calendar date2 = GregorianCalendar.getInstance(); // creates a new calendar instance
    date2.setTime(date); 
    long now = date2.getTimeInMillis();
    long zaagmans = wednes - now;
    System.out.println("time "+date2.getTime());
    long Hour = date2.get(Calendar.HOUR_OF_DAY);
    Hour = Hour - 13;
    long Minute = date2.get(Calendar.MINUTE);
    long Seconds = date2.get(Calendar.SECOND);
    long mSeconds = date2.get(Calendar.MILLISECOND);
    float total = (mSeconds + (1000*Seconds) + (60*1000 * Minute) + (60*60*1000 * Hour));

    zaagmans = (long) (zaagmans - total);
    long days  = zaagmans / (1000*60*60*24);
    long hours = zaagmans / (1000*60*60) ;
    long mins  = zaagmans / (1000*60) ;
    long  secs  =  zaagmans / 1000 ;
    long dd = days;
    long  hh = hours - days  * 24;
    long  mm = mins  - hours * 60;
    long  ss = secs  - mins  * 60;
    System.out.println(date2);
    date2.clear();
    return ("Dagen: "+dd+", Uren: "+hh+", Minuten: "+mm+", Seconden: "+ss+"  ");
}
public void refresh(){
    Calendar calendar = Calendar.getInstance();
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    hour = hour + 2; 
     if(day==4 && hour >= 12){
    System.out.println("woensdag");
      setContentView(R.layout.zaagmans);
     }
     else if(day==5){
       System.out.println("donderdag");
         setContentView(R.layout.zaagmans);
        }
     else if(day==6 && hour <= 17){
       System.out.println("vrijdag");
         setContentView(R.layout.zaagmans);
        }
     else if(day==6 && hour > 17){
       System.out.println("vrijdag"); 
     setContentView(R.layout.weekend);
     }
     else if(day==7 || day==1){
       System.out.println("Weekend");
     setContentView(R.layout.weekend);
     }
     else{
       setContentView(R.layout.jammer);
       showtext.run();
     }
  }


   }

And here is my log

10-25 14:03:21.200: W/dalvikvm(12287): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
10-25 14:03:21.210: E/AndroidRuntime(12287): FATAL EXCEPTION: main
10-25 14:03:21.210: E/AndroidRuntime(12287): java.lang.NullPointerException
10-25 14:03:21.210: E/AndroidRuntime(12287):    at nl.zaagmans.ZaagmanActivity$5.run(ZaagmanActivity.java:128)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at nl.zaagmans.ZaagmanActivity$2.onClick(ZaagmanActivity.java:93)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at android.view.View.performClick(View.java:2532)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at android.view.View$PerformClick.run(View.java:9293)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at android.os.Handler.handleCallback(Handler.java:587)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at android.os.Looper.loop(Looper.java:143)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at android.app.ActivityThread.main(ActivityThread.java:4263)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at java.lang.reflect.Method.invokeNative(Native Method)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at java.lang.reflect.Method.invoke(Method.java:507)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-25 14:03:21.210: E/AndroidRuntime(12287):    at dalvik.system.NativeStart.main(Native Method)
  • 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-05-26T12:10:06+00:00Added an answer on May 26, 2026 at 12:10 pm

    The line

    t=(TextView)findViewById(R.id.t);
    

    returns null, because your run method isn’t in a scope of any layout file. The code doesn’t make any sense btw, as you’re creating an object and assign it to t right before doing this assignment.

    And please don’t post your full source code, only post the relevant parts.

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

Sidebar

Related Questions

This question occured to me while programming a Android application, but it seems to
I've run into some trouble in my programming book while completing an exercise to
While programming, the longest part is a build on my ASP.NET Website project is
Sometimes I need to learn the type of an expression while programming in C
What specific techniques have you found to learn keyboard shortcuts while programming? I don't
I'm a VMware user and far too often I use keyboard shortcuts while programming.
I've just started using ASP, so while programming the code behind in C# I
While computer programming evangelists predicting the future of Cloud Computing to be very bright,
While not entirely programming related. I recently purchased a SSL certificate, and during the
i've been programming a while in D (http://www.digitalmars.com/d/) now. I prefer it to Java

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.