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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:18:02+00:00 2026-06-07T05:18:02+00:00

When I run an activity in my Android app with instantiating dbs classes as

  • 0

When I run an activity in my Android app with instantiating dbs classes as follows:

private final DbOpenHelper dbOpen = new DbOpenHelper(MainMonitor.this);
private final SQLiteDatabase db = dbOpen.getWritableDatabase();
private final ContentValues cv = new ContentValues();   

it falls with exception:

    07-10 15:33:31.581: E/AndroidRuntime(1142): FATAL EXCEPTION: main
07-10 15:33:31.581: E/AndroidRuntime(1142): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.analizer/com.android.analyzer.MainMonitor}: java.lang.NullPointerException
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.os.Looper.loop(Looper.java:137)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.app.ActivityThread.main(ActivityThread.java:4340)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at java.lang.reflect.Method.invokeNative(Native Method)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at java.lang.reflect.Method.invoke(Method.java:511)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at dalvik.system.NativeStart.main(Native Method)
07-10 15:33:31.581: E/AndroidRuntime(1142): Caused by: java.lang.NullPointerException
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at com.android.analyzer.MainMonitor.<init>(MainMonitor.java:40)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at java.lang.Class.newInstanceImpl(Native Method)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at java.lang.Class.newInstance(Class.java:1319)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
07-10 15:33:31.581: E/AndroidRuntime(1142):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
07-10 15:33:31.581: E/AndroidRuntime(1142):     ... 11 more

DbOpenHelper looks like this:

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DbOpenHelper extends SQLiteOpenHelper {

    private static final String DB_NAME = "analyzer";
    private static final int DB_VERSION = 1;

    public static final String TABLE_NAME = "network";
    public static final String ACTIVITY = "activity";

    public static final String CREATE_TABLE_NETWORK = "CREATE TABLE "+TABLE_NAME+"(" +
            "_id integer primary key autoincrement, activity integer default 1)"; 

//  DbOpenHelper openHelper = null;

    public DbOpenHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
//      openHelper = new DbOpenHelper(context);

    }

    public void onCreate(SQLiteDatabase sqliteDb) {
        sqliteDb.execSQL(CREATE_TABLE_NETWORK);
        sqliteDb.execSQL("INSERT INTO network(activity) VALUES(1)");
    }

    public void onUpgrade(SQLiteDatabase sqliteDb, int i, int i2) {

    }

//  @Override
//  public void close() {
//      if (openHelper!=null) openHelper.close();       
//  }

}

The problem solved, but the next problem appeared. I’ve put the insert method in the DbOpenHelper class like this:

    public void onCreate(SQLiteDatabase sqliteDb) {
        sqliteDb.execSQL(CREATE_TABLE_NETWORK);
//      sqliteDb.execSQL("INSERT INTO network(activity) VALUES(1)");
        ContentValues cv = new ContentValues();
        cv.put(ACTIVITY_FIELD, 1);
        sqliteDb.insert(DbOpenHelper.TABLE_NAME, null, cv);
    }

And in Activity I’m trying to update table this way:

                    cv.put(DbOpenHelper.ACTIVITY_FIELD, 0);
//                  db.insert(DbOpenHelper.TABLE_NAME, null, cv);
                    db.update(DbOpenHelper.TABLE_NAME, cv, null, null);

An Exception is:
07-11 15:02:47.341: E/AndroidRuntime(933): FATAL EXCEPTION: main
07-11 15:02:47.341: E/AndroidRuntime(933): java.lang.NullPointerException
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.database.sqlite.SQLiteStatement.releaseAndUnlock(SQLiteStatement.java:290)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:96)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1810)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1761)
07-11 15:02:47.341: E/AndroidRuntime(933):  at com.android.analyzer.MainMonitor$2.onCheckedChanged(MainMonitor.java:99)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.widget.CompoundButton.setChecked(CompoundButton.java:125)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.widget.Switch.setChecked(Switch.java:517)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.widget.Switch.animateThumbToCheckedState(Switch.java:508)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.widget.Switch.stopDrag(Switch.java:498)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.widget.Switch.onTouchEvent(Switch.java:458)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.View.dispatchTouchEvent(View.java:5486)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1728)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1728)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1728)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1728)
07-11 15:02:47.341: E/AndroidRuntime(933):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1892)
07-11 15:02:47.341: E/AndroidRuntime(933):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1371)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
07-11 15:02:47.341: E/AndroidRuntime(933):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1840)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.View.dispatchPointerEvent(View.java:5662)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2863)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.os.Looper.loop(Looper.java:137)
07-11 15:02:47.341: E/AndroidRuntime(933):  at android.app.ActivityThread.main(ActivityThread.java:4340)
07-11 15:02:47.341: E/AndroidRuntime(933):  at java.lang.reflect.Method.invokeNative(Native Method)
07-11 15:02:47.341: E/AndroidRuntime(933):  at java.lang.reflect.Method.invoke(Method.java:511)
07-11 15:02:47.341: E/AndroidRuntime(933):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-11 15:02:47.341: E/AndroidRuntime(933):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-11 15:02:47.341: E/AndroidRuntime(933):  at dalvik.system.NativeStart.main(Native Method)

I found this line helpfull –

at com.android.analyzer.MainMonitor$2.onCheckedChanged(MainMonitor.java:99)

and it seems like no table or/and row was created in dbs, that’s why it couldn’t update itself. What is the problem with this awefully drag-like sqlite? =)

  • 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-07T05:18:04+00:00Added an answer on June 7, 2026 at 5:18 am

    The Activity is created only after onCreate calling. So when you are calling
    private final DbOpenHelper dbOpen = new DbOpenHelper(MainMonitor.this);
    activity still not created.
    Remove final modifier from your db option and init it in separate method after onCreate calling.

    You should do smth like this:

    public class MainMonitor extends Activity {
    private DbOpenHelper dbOpen;
    private SQLiteDatabase db;
    private ContentValues cv;
    
    @Override
    protected void onResume() {
        super.onResume();
    
        initDb();
    }
    
    private void initDb() {
        dbOpen = new DbOpenHelper(MainMonitor.this);
        db = dbOpen.getWritableDatabase();
        cv = new ContentValues();
    }
    
    //....your code
    

    }

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

Sidebar

Related Questions

I try to run this code on emulator: package andr.andr; import android.app.Activity; import android.content.Context;
aka, what is wrong with this code:- package com.mez.appofjaq; import com.mez.appofjaq.RssParser.RssFeed; import android.app.Activity; import
When I run an android app from eclipse I meet this error and my
I have an example like this: package android.uiexample; import android.app.Activity; import android.os.Bundle; import android.os.Handler;
I have a login page (an activity in Android), during which I run an
When I run my code, Unable to start activity ComponentInfo: android.database.sqlite.SQLiteException: near /: syntax
I have a lot of buttons on main activity. Each button run this same
Possible Duplicate: Why does Android app run in small window on tablet emulator? i
A simple android Hello World: MainActivity.java: package com.amaker.ch02.app; import android.app.Activity; import android.os.Bundle; import android.widget.TextView;
I'm new to Android development. I'm trying to get a simple HelloWorld app going

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.