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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:26:42+00:00 2026-05-29T06:26:42+00:00

I wrote an Android widget with alarmmanager as updating process. Sometimes i’ve got a

  • 0

I wrote an Android widget with alarmmanager as updating process. Sometimes i’ve got a nullpointer exception. But all objects are initialized…

public void UpdateWidget(Context con)
{
    //Log.d("berlinClock", "UpdateWidget="+i);
    RemoteViews views=new RemoteViews(con.getPackageName(),R.layout.widgetlayout);
    Calendar c = Calendar.getInstance(); 
    int h = c.get(Calendar.HOUR_OF_DAY);
    int m = c.get(Calendar.MINUTE);

    ComponentName thisWidget = new ComponentName(con,widget.class);

    //update views on remoteView
    // GOT NULLPOINTER EXEPTION IN FOLLOWING LINE
    views.setImageViewResource(R.id.wha1, R.drawable.cgrau);
    views.setImageViewResource(R.id.wha2, R.drawable.cgrau);
    ...
    }

Here is the Stacktrace:

java.lang.RuntimeException: Unable to start receiver ms.jung.android.berlinclock.widget: java.lang.NullPointerException
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
at android.app.ActivityThread.access$3200(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at ms.jung.android.berlinclock.widget.UpdateWidget(widget.java:96)
at ms.jung.android.berlinclock.widget.onReceive(widget.java:34)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
  • 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-29T06:26:43+00:00Added an answer on May 29, 2026 at 6:26 am
    if(views!=null)
    {
        ...
    }
    

    With this if condition it will not crash anymore, i saw that solution now in many examples, and i think that is the best way to do that.

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

Sidebar

Related Questions

I wrote a widget for Android and I'm trying to get the battery level.
I've got a serious problem with my GPS on my Nexus One: I wrote
I wrote a widget that can call numbers directly with one click. It works
I wrote a code for pinging of given URL.It works fine for me.But whenever
I'm trying to write an Android widget that shows how much data has been
I just started to learn Android, I'm trying to write a widget which is
I'm trying to use the NumberPicker widget in Android 3.1. I figure it is
I wrote an Android application. These are the permissions I requested: INTERNET ACCESS-COARSE-LOCATION ACCESS-FINE-LOCATION
I wrote an application using the Android 2.2 SDK (API level 8). It is
For get device id in android sdk i wrote simple This code :: import

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.