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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:10:20+00:00 2026-06-09T09:10:20+00:00

when I insert record that time I face the below problem: java.lang.runtimeexception unable to

  • 0

when I insert record that time I face the below problem:
java.lang.runtimeexception unable to start activity componentinfo java.lang.nullpointerexception.I am getting null pointer exception while inserting values into sqlite database. The dh in DatabaseHelper dh = new DatabaseHelper(this) is coming out to be null when I try to check its value by putting a breakpoint. Below is the code of my DatabaseHelper class and the class from where I am trying to insert the values.

First Activity : DbActivity.java

package com.example.dbhelpersimple;

import android.os.Bundle;
import android.provider.Contacts;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import android.support.v4.app.NavUtils;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;

public class DbActivity extends SQLiteOpenHelper {

    public static final String COL_NAME = "name";
    public static final String COL_CNT = "contact";
    private static final String DATABASE_TABLE = "test";
    private static String DATABASE_NAME = "PERSONS.db";

    private static final String DATABASE_CREATE="CREATE TABLE test"+
            "(name VARCHAR(10), contact VARCHAR(10));";





    SQLiteDatabase db;





    public DbActivity(Context context) {
        super(context, DATABASE_NAME, null, 1);
        // TODO Auto-generated constructor stub
    }









    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(DATABASE_CREATE);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

        db.execSQL(DATABASE_NAME);
        onCreate(db);
    }

    void addrecord(String name, String contact)
    {
        ContentValues cv=new ContentValues();
        cv.put(COL_NAME, name);
        cv.put(COL_CNT, contact);
        db.insert(DATABASE_TABLE, null, cv);
        db.close();
    }


    void getrecords()
    {
        int i;
        //String query="SELECT * FROM test";
        Cursor c=db.query(DATABASE_TABLE, null, null, null, null, null, null);
        c.moveToFirst();

        while(c.isAfterLast()==false)
        {
            Log.d("Name", c.getString(0));
            Log.d("Contact", c.getString(1));
        }



    }


}

Second Activity: manipulateActivity.java

package com.example.dbhelpersimple;

import android.app.Activity;

import android.os.Bundle;

import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import android.widget.SimpleAdapter;


public class manipulateActivity extends Activity{

    Button btn1,btn2,btn3;

      EditText edt1,edt2;


     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_db);

            edt1=(EditText)findViewById(R.id.edittextname);
            edt2=(EditText)findViewById(R.id.edittextcontact);

    DbActivity dbact= new DbActivity(this);

    dbact.addrecord("sagar", "111");




     }

}
  • 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-09T09:10:22+00:00Added an answer on June 9, 2026 at 9:10 am

    First Activity : DbActivity.java

    private final Context context;
    
    public DbActivity(Context context)
        {
    
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        this.context = context;
    
        }
    private static final String DATABASE_CREATE =
                   "create table test (_id integer primary key autoincrement, "
                   + "name text Not Null, contact text Not Null);";
    
    @Override
    public void onCreate(SQLiteDatabase database) {
        database.execSQL(DATABASE_CREATE);
    
    
    }
    

    Second Activity: ManipulateActivity.java

    private DbActivity dbHelper;
    
    private Context context;
    
    public ManipulateActivity(Context context) {
        this.context = context;
    }
    
     dbHelper = new DbActivity(context);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySql database that stores a timestamp for each record I insert.
I have an ADOQuery that inserts a record to SQL Server 2005 table that
I am developing a test application that requires me to insert 1 million records
I am trying to identify SQL INSERTS that occur when a record is viewed
I'am trying to insert record into db2 table and getting a result with response.write.
I want to insert a record into a MySQL database table from a formulaire.
how can insert a record if only a specific value doesn't exist in a
I'm trying to insert a record into the database but it is giving me
I am trying to insert a record into a table using Linq but get
I'm trying to insert a record (on LINQ to SQL) to the database. So

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.