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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:12:54+00:00 2026-06-19T04:12:54+00:00

I try to INSERT data from db_insert.java and process by method in MyDB.java .

  • 0

I try to INSERT data from db_insert.java and process by method in MyDB.java.

public void append(String n,int p) { 
      String str = "INSERT INTO " + TABLE_NAME + " (" + NAME + "," + PRICE + ") VALUES (" + n +"," + p + ")";
        db.execSQL(str);      
}

In Debug mode, n & p get data from db_insert.java.

So far, it’s fine. But when process db.execSQL(str);, the app will crash.

Does somebody know why?

logcat

    02-07 00:16:48.467: I/Process(979): Sending signal. PID: 979 SIG: 9 02-07 00:17:17.827:

 E/MyDBlog(1109): click insert_OKs 02-07 00:17:17.827: D/AndroidRuntime(1109): Shutting 


down VM 02-07 00:17:17.827: W/dalvikvm(1109): threadid=1: thread exiting with uncaught 

exception (group=0x2aac8578) 02-07 00:17:17.827: E/AndroidRuntime(1109): FATAL EXCEPTION: 

main 02-07 00:17:17.827: E/AndroidRuntime(1109): java.lang.NullPointerException 02-07 

00:17:17.827: E/AndroidRuntime(1109): at com.example.mydb.MyDB.append(MyDB.java:39) 02-07 

00:17:17.827: E/AndroidRuntime(1109): at com.example.mydb.db_insert$1.onClick(db_insert.java:66) 02-07 00:17:17.827: 

E/AndroidRuntime(1109): at android.view.View.performClick(View.java:2552) 02-07 

00:17:17.827: E/AndroidRuntime(1109): at android.view.View$PerformClick.run(View.java:9229) 

02-07 00:17:17.827: E/AndroidRuntime(1109): at android.os.Handler.handleCallback(Handler.java:587) 02-07 00:17:17.827: 

E/AndroidRuntime(1109): at android.os.Handler.dispatchMessage(Handler.java:92) 02-07 

00:17:17.827: E/AndroidRuntime(1109): at android.os.Looper.loop(Looper.java:130) 02-07 

00:17:17.827: E/AndroidRuntime(1109): at android.app.ActivityThread.main(ActivityThread.java:3701) 02-07 00:17:17.827: E/AndroidRuntime(1109): at java.lang.reflect.Method.invokeNative(Native Method) 02-07 00:17:17.827: E/AndroidRuntime(1109): at java.lang.reflect.Method.invoke(Method.java:507) 02-07 00:17:17.827: E/AndroidRuntime(1109): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 02-07 

00:17:17.827: E/AndroidRuntime(1109): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 02-07 00:17:17.827: 

E/AndroidRuntime(1109): at dalvik.system.NativeStart.main(Native Method)

My app first use open() to open DB.

MyDB.java

public SQLiteDatabase db=null; 
private Context mCtx = null;
public MyDB(Context ctx){  
    this.mCtx = ctx;      
}
public void open() throws SQLException { // 開啟已經存在的資料庫  
    db = mCtx.openOrCreateDatabase(DATABASE_NAME, 0, null);
        try {       
          db.execSQL(CREATE_TABLE);// 建立資料表 
      }catch (Exception e) {    
      } 
  }
  • 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-19T04:12:55+00:00Added an answer on June 19, 2026 at 4:12 am
    private static final String INSERT = "insert into contact(name,number) values(?,?)";
    public DataHelper(Context context)
        {
            this.context=context;
            openhelper=new OpenHelper(context);
            this.db=openhelper.getWritableDatabase();
            this.insertStmt1 = this.db.compileStatement(INSERT);
    
        }
    
    public boolean insert(String name, String number)
        {
        openhelper=new OpenHelper(context);
        db=openhelper.getWritableDatabase();
    
        String person=name;
    
    
        String values1=number;
    
        this.insertStmt1.bindString(1, person);
        this.insertStmt1.bindString(2, number);
    
        this.insertStmt1.executeInsert();
    
       Toast.makeText(context, "Value inserted", 10000).show();
        openhelper.Close_DB(db); 
        return true;
        }
    

    This is an example to insert value into database modify this as per your needs. 🙂

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

Sidebar

Related Questions

i am new to java, i am trying to insert a data from old_db
When i try to insert the value from the textbox into the database, the
I have problem when I try insert some data to Informix TEXT column via
I read a set of data from database first Insert a new record using
Hi i am using follwing code to insert bulk data from arrays into sqlite
I've a problem when I try to insert data into a hsqldb with a
When I try to add the data from a form to my DB it
This is my DataBase Manager Class public class MyDbManager { private String DB_NAME=MyDb; private
I wrote a query to insert data from .lst file into table name AxisATM
I have the following method being called in a Java EE web application. public

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.