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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:35:42+00:00 2026-06-17T00:35:42+00:00

Everything has been working as usual until now: when I click on a button

  • 0

Everything has been working as usual until now: when I click on a button I have clicked a hundred times, suddenly I get a NullPointerException.

This is the relevant code:

View dbButton = findViewById(R.id.db_button);
dbButton.setOnClickListener(this);


public void onClick (View v) {
    switch (v.getId()) {
    case R.id.new_sms_button:
        Intent inte = new Intent(this, NewSMS.class);
        startActivity(inte);
        break;
    case R.id.about_button:
        Intent i = new Intent(this, About.class);
        startActivity(i);
        break;
    case R.id.db_button:
        Intent in = new Intent(this, Profile.class); duplicata
        startActivity(in);
        break;
    case R.id.prefs_button:
        Intent intent1 = new Intent(this, Settings.class);
        startActivity(intent1);
        break;
    }
}

And this is the Profile class:

public class Profile extends Activity {

private UsersData usersData;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.userprofile);

    usersData = new UsersData(this);
    Cursor cursor = getUserData();
    showUserData(cursor);
}

private static String[] FROM = { PHONE_NUMBER, SMS_SENT, SMS_RECEIVED, };
private Cursor getUserData() {
    SQLiteDatabase db = usersData.getReadableDatabase();
    Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null, null, null);
    startManagingCursor(cursor);
    return cursor;
}

private void showUserData(Cursor cursor) {
    StringBuilder builder = new StringBuilder("Data:\n");
    while (cursor.moveToNext()) {
        String num = cursor.getString(0);
        long smss = cursor.getLong(1);
        long smsr = cursor.getLong(2);
        builder.append("num: ").append(num).append("\n");
        builder.append("sent: ").append(smss).append("\n");
        builder.append("received: ").append(smsr).append("\n");
    }
    TextView text = (TextView) findViewById(R.id.userdata);
    text.setText(builder);
}
}

LogCat:

01-10 14:16:56.655: E/AndroidRuntime(2550): FATAL EXCEPTION: main
01-10 14:16:56.655: E/AndroidRuntime(2550): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app/com.app.Profile}: java.lang.NullPointerException
01-10 14:16:56.655: E/AndroidRuntime(2550):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at android.os.Looper.loop(Looper.java:123)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at android.app.ActivityThread.main(ActivityThread.java:3683)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at java.lang.reflect.Method.invokeNative(Native Method)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at java.lang.reflect.Method.invoke(Method.java:507)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at dalvik.system.NativeStart.main(Native Method)
01-10 14:16:56.655: E/AndroidRuntime(2550): Caused by: java.lang.NullPointerException
01-10 14:16:56.655: E/AndroidRuntime(2550):     at com.rpgsms.Profile.showUserData(Profile.java:78)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at com.rpgsms.Profile.onCreate(Profile.java:50)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-10 14:16:56.655: E/AndroidRuntime(2550):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

UsersData is the app’s database class. Any idea why this is happening?

  • 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-17T00:35:43+00:00Added an answer on June 17, 2026 at 12:35 am

    It’s difficult to tell which statement Profile.java:78 is, but it’s possibly the Cursor parameter being null caused by a failure in db.query(). You need to add more error checking and report them via Log.e().

    And incidentally you can simplify your onClick() method rather than creating multiple Intents with different names:

    public void onClick (View v) {
        Intent intent = null;
        switch (v.getId()) {
        case R.id.new_sms_button:
            intent = new Intent(this, NewSMS.class);
            break;
        case R.id.about_button:
            intent = new Intent(this, About.class);
            break;
        case R.id.db_button:
            intent = new Intent(this, Profile.class);
            break;
        case R.id.prefs_button:
            intent = new Intent(this, Settings.class);
            break;
        default:
            break;
        }
    
        if (intent != null) {
            startActivity(intent);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm developing and iPhone game right now and everything has been working just
I'm currently working on a project, and everything has been going well up until
I have a test server which has been working up until recently. Its running
Up until recently everything has been working fine in Eclipse and when I double
I'm using Ninject, Fluent NHibernate and ASP.NET MVC. Up until now everything has been
I have a jQuery Autocomplete field on an ASP.Net Webform and everything has been
This has been driving me crazy. I think I have everything in place but
I have a div whose position has been fixed. Everything is fine till the
I finished my site a month ago and everything has been working great. I
I've been working on this site for the past two weeks and everything has

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.