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

  • Home
  • SEARCH
  • 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 8298599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:50:15+00:00 2026-06-08T15:50:15+00:00

So, making an app. I added loads of new code, and now it FC’s

  • 0

So, making an app. I added loads of new code, and now it FC’s on open 🙁

Here is the logcat:

07-25 16:59:12.490: D/AndroidRuntime(26121): Shutting down VM
07-25 16:59:12.495: W/dalvikvm(26121): threadid=1: thread exiting with uncaught exception (group=0x40a641f8)
07-25 16:59:12.495: E/AndroidRuntime(26121): FATAL EXCEPTION: main
07-25 16:59:12.495: E/AndroidRuntime(26121): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.liamwli.smsbusy/com.liamwli.smsbusy.Sms_busyActivity}: java.lang.NullPointerException
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1993)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.app.ActivityThread.access$600(ActivityThread.java:132)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.os.Looper.loop(Looper.java:137)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.app.ActivityThread.main(ActivityThread.java:4575)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at java.lang.reflect.Method.invokeNative(Native Method)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at java.lang.reflect.Method.invoke(Method.java:511)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at dalvik.system.NativeStart.main(Native Method)
07-25 16:59:12.495: E/AndroidRuntime(26121): Caused by: java.lang.NullPointerException
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:371)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:366)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at com.liamwli.smsbusy.Sms_busyActivity.<init>(Sms_busyActivity.java:23)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at java.lang.Class.newInstanceImpl(Native Method)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at java.lang.Class.newInstance(Class.java:1319)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
07-25 16:59:12.495: E/AndroidRuntime(26121):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1984)
07-25 16:59:12.495: E/AndroidRuntime(26121):    ... 11 more
07-25 16:59:12.940: I/dalvikvm(26121): threadid=3: reacting to signal 3
07-25 16:59:12.950: I/dalvikvm(26121): Wrote stack traces to '/data/anr/traces.txt'
07-25 16:59:13.040: I/dalvikvm(26121): threadid=3: reacting to signal 3
07-25 16:59:13.045: I/dalvikvm(26121): Wrote stack traces to '/data/anr/traces.txt'

Line 23 of Sms_busyActivity.java is:

SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

I don’t understand what I am getting this error.

The rest of the activity is below (It is quite large):

package com.liamwli.smsbusy;

import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.content.IntentFilter;
import android.content.SharedPreferences;

public class Sms_busyActivity extends Activity {
    IntentFilter intentFilter;
    ToggleButton endis;
    EditText message;
    Button smessage;
    SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    SharedPreferences.Editor editor = getPrefs.edit();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Intent i = new Intent("com.liamwli.smsbusy.PREFS");
        // startActivity(i);
        setContentView(R.layout.main);

        endis = (ToggleButton) findViewById(R.id.enableddis);

        smessage = (Button) findViewById(R.id.savemess);

        message = (EditText) findViewById(R.id.message);

        // ---intent to filter for SMS messages received---
        intentFilter = new IntentFilter();
        intentFilter.addAction("SMS_RECEIVED_ACTION");

        endis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // TODO Auto-generated method stub
                Toast.makeText(Sms_busyActivity.this, "App state changed",
                        Toast.LENGTH_LONG).show();
                if (endis.isChecked()){
                    editor.putBoolean("enabled", true);
                    editor.commit();
                }else {
                    editor.putBoolean("enabled", false);
                    editor.commit();
                }

                editor.putString("message", message.getText().toString());
                editor.commit();

            }
        });

        smessage.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                editor.putString("message", message.getText().toString());
                editor.commit();

            }
        });

    }

    @SuppressWarnings("deprecation")
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (Integer.parseInt(android.os.Build.VERSION.SDK) < 5
                && keyCode == KeyEvent.KEYCODE_BACK
                && event.getRepeatCount() == 0) {
            Log.d("CDA", "onKeyDown Called");
            onBackPressed();
        }

        return super.onKeyDown(keyCode, event);
    }

    public void onBackPressed() {
        Log.d("CDA", "onBackPressed Called");

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        return super.onCreateOptionsMenu(menu);
    }

}

Please can someone help me?

  • 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-08T15:50:17+00:00Added an answer on June 8, 2026 at 3:50 pm

    Move the following code to within the onCreate() method.

    getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    

    The reason being, in your existing code, you’re using the context (getBaseContext()) before it could be fully created by a call to super.onCreate().

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

Sidebar

Related Questions

I'm making Rails 3.1.1 app and trying to add some jQuery code to it.
I ran the HelloWorld android app and now I moved on to making buttons
I am making an app in which I have to delete the recently added
EDIT : I'm making an app like a Slot Machine, i added iCarousel for
i'm making app that the main page include TableView but i want when i
I am making app that takes a screenshot of a URL requested by the
I am making app about google documents. but I don't know How to save
i m making APP which do image proceesing using java SE.i want to check
Im making an app that should let the user see video from the camera
Iam making an app which has one index.php file. I also have these other

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.