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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:27:39+00:00 2026-06-13T21:27:39+00:00

I am trying to receive a row id from from a main activity and

  • 0

I am trying to receive a row id from from a main activity and from there, display the content of that row. However I am getting a null pointer exception. I’m unsure of how to implement this properly.

The exception is related to line 22 MODULEDATABASE.openToRead(); I am an unsure if I need to open to read as I have done this in the main activity. If I comment out this line the next error refers to line 23 cursor = MODULEDATABASE.getRow(rowId); Any suggestions would be much appreciated

LogCat error from **MODULEDATABASE.openToRead();

    10-23 09:12:52.572: E/AndroidRuntime(19778): Uncaught handler: thread main exiting due to uncaught exception
10-23 09:12:52.582: E/AndroidRuntime(19778): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mycoursetimetable/com.example.mycoursetimetable.ViewCourse}: java.lang.NullPointerException
10-23 09:12:52.582: E/AndroidRuntime(19778):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at android.os.Looper.loop(Looper.java:123)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at android.app.ActivityThread.main(ActivityThread.java:4363)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at java.lang.reflect.Method.invokeNative(Native Method)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at java.lang.reflect.Method.invoke(Method.java:521)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at dalvik.system.NativeStart.main(Native Method)
10-23 09:12:52.582: E/AndroidRuntime(19778): Caused by: java.lang.NullPointerException
10-23 09:12:52.582: E/AndroidRuntime(19778):    at com.example.mycoursetimetable.ViewCourse.onCreate(ViewCourse.java:22)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-23 09:12:52.582: E/AndroidRuntime(19778):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
10-23 09:12:52.582: E/AndroidRuntime(19778):    ... 11 more
10-23 09:12:52.603: I/dalvikvm(19778): threadid=7: reacting to signal 3
10-23 09:12:52.603: E/dalvikvm(19778): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
10-23 09:12:59.232: I/Process(19778): Sending signal. PID: 19778 SIG: 9

LogCat cursor = MODULEDATABASE.getRow(rowId);

10-23 09:16:42.923: E/AndroidRuntime(20316): Uncaught handler: thread main exiting due to uncaught exception
10-23 09:16:42.933: E/AndroidRuntime(20316): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mycoursetimetable/com.example.mycoursetimetable.ViewCourse}: java.lang.NullPointerException
10-23 09:16:42.933: E/AndroidRuntime(20316):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at android.os.Looper.loop(Looper.java:123)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at android.app.ActivityThread.main(ActivityThread.java:4363)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at java.lang.reflect.Method.invokeNative(Native Method)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at java.lang.reflect.Method.invoke(Method.java:521)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at dalvik.system.NativeStart.main(Native Method)
10-23 09:16:42.933: E/AndroidRuntime(20316): Caused by: java.lang.NullPointerException
10-23 09:16:42.933: E/AndroidRuntime(20316):    at com.example.mycoursetimetable.ViewCourse.onCreate(ViewCourse.java:23)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-23 09:16:42.933: E/AndroidRuntime(20316):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
10-23 09:16:42.933: E/AndroidRuntime(20316):    ... 11 more
10-23 09:16:42.953: I/dalvikvm(20316): threadid=7: reacting to signal 3
10-23 09:16:42.953: E/dalvikvm(20316): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
10-23 09:16:44.633: I/Process(20316): Sending signal. PID: 20316 SIG: 9

View Course activity

public class ViewCourse extends Activity {
Cursor cursor;
database MODULEDATABASE;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_course);

        Intent intent = getIntent();
        String rowId = intent.getStringExtra(MyCourses.TEST);
        //MODULEDATABASE.openToRead();
        cursor = MODULEDATABASE.getRow(rowId);

        TextView text_modulecode = (TextView)findViewById(R.id.viewModuleCode);
        TextView text_modulename = (TextView)findViewById(R.id.viewModuleName);

        text_modulecode.setText(cursor.getString(cursor.getColumnIndex(database.KEY_MODULECODE)));
        text_modulename.setText(cursor.getString(cursor.getColumnIndex(database.KEY_MODULENAME)));

    }

Database Class

public  database openToRead()throws SQLException{
        myHelper = new DbHelper(myContext);
        moduleDatabase = myHelper.getReadableDatabase();
        return this;
}

public Cursor getRow(String rowId)
    {
        String[] columns = new String [] {KEY_ROWID,KEY_MODULECODE, KEY_MODULENAME};
        Cursor c = moduleDatabase.query(DATABASE_TABLE, columns,KEY_ROWID+ "="+rowId , null, null, null, null);
        if(c!=null){
            c.moveToFirst();
        }
        return c;
    }
  • 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-13T21:27:40+00:00Added an answer on June 13, 2026 at 9:27 pm

    I’d check what myContext is.

    myHelper = new DbHelper(myContext);
    

    You have created MODULEDATABASE as a global which is correct however you need to initialize the object in your onCreate method of the Course activity. Ensure that the initialization of the database object accepts the context from your Course activity. That is, have a constructor that has a parameter for the course activity to pass its context over.

    In your Course Activity you should be able to do the following…

    database MODULEDATABASE;
    public void onCreate(...) {
        MODULEDATABASE= new database(getApplicationContext()); 
    } 
    

    EDIT: The solution above gives the correct context when creating the object. Using ADR’s solution and instead of ViewCourse.this, use getApplicationContext() should give you another way of doing this.

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

Sidebar

Related Questions

I'm trying to display html text received from the server in a datatable row.
I am trying to receive a json object back from php after sending data
I am trying to receive an image from the Android Gallery via an ACTION_SEND
I seem to be getting this particular always when i am trying to receive
I am trying to develop the XMPP Gateway which can send/receive from standard XMPP
I'm trying to calculate the time it takes to receive all data from a
I receive an error when trying to get a certificate hash from a remote
I'm new to Ruby. I'm trying to make an app that reads from a
I have a dataframe with Address, City, State, Zip entities. From there, I'm trying
I am getting random row from my table using the following query: SELECT value_id

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.