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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:03:07+00:00 2026-06-18T11:03:07+00:00

My On Boot Receiver keeps crashing : 01-06 03:20:13.861: E/AndroidRuntime(15832): FATAL EXCEPTION: main 01-06

  • 0

My On Boot Receiver keeps crashing :

   01-06 03:20:13.861: E/AndroidRuntime(15832): FATAL EXCEPTION: main
01-06 03:20:13.861: E/AndroidRuntime(15832): java.lang.RuntimeException: Unable to start receiver com.example.prva.OnBootReceiver: java.lang.NullPointerException
01-06 03:20:13.861: E/AndroidRuntime(15832):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2043)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at android.app.ActivityThread.access$2400(ActivityThread.java:132)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1098)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at android.os.Looper.loop(Looper.java:143)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at android.app.ActivityThread.main(ActivityThread.java:4277)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at java.lang.reflect.Method.invokeNative(Native Method)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at java.lang.reflect.Method.invoke(Method.java:507)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at dalvik.system.NativeStart.main(Native Method)
01-06 03:20:13.861: E/AndroidRuntime(15832): Caused by: java.lang.NullPointerException
01-06 03:20:13.861: E/AndroidRuntime(15832):    at com.example.prva.DatabaseManager.getAllData(DatabaseManager.java:91)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at com.example.prva.OnBootReceiver.onReceive(OnBootReceiver.java:32)
01-06 03:20:13.861: E/AndroidRuntime(15832):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2028)
01-06 03:20:13.861: E/AndroidRuntime(15832):    ... 10 more

Broadcast receiver :

@Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Calendar c2 = Calendar.getInstance();               
        int hour = c2.get(Calendar.HOUR_OF_DAY);
        int minute = c2.get(Calendar.MINUTE);
        int sek = c2.get(Calendar.SECOND);

        int dan;
        int dodaj;

        milivreme = ((hour * 60 * 60 * 1000)+ (minute * 60 * 1000) + (sek * 1000));

        Cursor cursor = DatabaseManager.getAllData();

        cursor.moveToFirst();
        if (!cursor.isAfterLast())
        {
            do
            {               
        milibaza = cursor.getInt(2);
        razlika = milibaza - milivreme;

        Intent intent1 = new Intent(context, AlarmReceiver.class);
        PendingIntent pendingintent = PendingIntent.getService(context, 3, intent1, PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager am = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);

        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + razlika, pendingintent);
            }
            while (cursor.moveToNext());
        }
        cursor.close(); 
    }

The getAllData method :

public static Cursor getAllData() {

        return db.query(TABLE_NAME, new String[] { TABLE_COLUMN_ID, TABLE_COLUMN_ONE, TABLE_COLUMN_TWO }, 
                null, null, null, null, null);       

    }   

Databse has records :

I have a button which displays last value from the database in a textview :

public void onClick(View v) {
                // TODO Auto-generated method stub
                String BazaDan;
                int BazaVrijeme;
                DatabaseManager.Cursoric();

                BazaDan = DatabaseManager.getDan();
                BazaVrijeme = DatabaseManager.getVrijeme();
                textbaza.setText(new StringBuilder(BazaDan).append(", ").append(BazaVrijeme).toString());
            }
        });

Method for Cursor that button is using :

public static void Cursoric(){

        Cursor cursor;
        cursor = db.query
                (
                        TABLE_NAME,
                        new String[] { TABLE_COLUMN_ID, TABLE_COLUMN_ONE, TABLE_COLUMN_TWO },                       
                        null, null, null, null, null
                );
        cursor.moveToFirst();
        if (!cursor.isAfterLast())
        {
            do
            {
                BazaDan = cursor.getString(1);
                BazaVrijeme = cursor.getInt(2);
            }
            while (cursor.moveToNext());
        }    

        cursor.close(); 
    }

As you can see its almost the same thing I’m using in BroadcastReceiver.
The textview after that button click displays from the database (last time I tested) :

1, 12120000 

Its day number, and miliseconds.

So records are being stored in the database, and they can be retrieved but OnBootReceiver keeps getting null pointer exception when booting while he is doing almost the same thing with cursor as that button.

  • 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-18T11:03:08+00:00Added an answer on June 18, 2026 at 11:03 am

    as in log :

    Caused by: java.lang.NullPointerException

    because db instance is null inside getAllData method so just make null check before using it as :

    public static Cursor getAllData()
    {
           Cursor cursor=null;
        if(db!=null)
        {
          cursor=db.query(TABLE_NAME, new String[] 
                  { TABLE_COLUMN_ID, TABLE_COLUMN_ONE, 
                  TABLE_COLUMN_TWO }, null,
                   null, null, null, null);
        }
    
    return cursor;
    }
    

    and also check cursor for NULL before using it inside onReceive method of BroadcastReceiver

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

Sidebar

Related Questions

I have a receiver that start after phone boot like this: <receiver android:name=.OnBootReceiver >
I have a boot complete broadcast receiver but it wasnt working as expected. Nor
I am having Boot Completed Receiver in my application and after Reboot completed, inside
I'm trying to run a simple on boot receiver. I just need to get
I used BroadcastReceiver to start my application on boot, but it is not starting
I need a service to start at boot that periodically checks some database for
I am trying to solve a start on boot related problem and I noticed
I have a broadcast receiver that on boot of the phone runs a pending
I am using a Boot receiver to fire AlarmManager,so that it repeats it's task
I'm trying to read data to my widget after device boot. My boot receiver

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.