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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:25:22+00:00 2026-05-23T07:25:22+00:00

I am new to Android following is my code I wants to add data

  • 0

I am new to Android following is my code I wants to add data in data base on the click of button but when I click on the Button my application crashes
can anybody suggest me any solution
here is my code:

public class Third extends Activity implements OnClickListener{
Button btn;
SQLiteDatabase db;
EditText edit1;
EditText edit2;
EditText edit3;

@Override
protected void onCreate(Bundle icicle) {
// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.mit);
SQLiteDatabase db;
db = openOrCreateDatabase("doctorinfo.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
final String CREATE_TABLE_COUNTRIES ="CREATE TABLE med_d ("+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"+ "DOC_NAME TEXT,"+ "DOC_NO TEXT,"+ "DOC_EMAIL TEXT);";
//db.execSQL(CREATE_TABLE_COUNTRIES);
btn=(Button)findViewById(R.id.button1);
edit1=(EditText)findViewById(R.id.editText1);
edit2=(EditText)findViewById(R.id.editText2);
edit3=(EditText)findViewById(R.id.editText3);

btn.setOnClickListener(this);


}

@Override
public void onClick(View arg0) {
String d=edit1.getText().toString();
String m=edit2.getText().toString();
String p=edit3.getText().toString();

ContentValues values = new ContentValues();
values.put("DOC_NAME",d );
values.put("DOC_NO",m);
values.put("DOC_EMAIL",p);
//long countryId = db.insert("med_d", null, values);
//try {
db.insertOrThrow("med_d", null,values);
}// catch (Exception e) {
//Log.e("Add Error", e.toString());
//e.printStackTrace();
//}



}
  • 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-05-23T07:25:23+00:00Added an answer on May 23, 2026 at 7:25 am

    SQLITEOPENHELPER CLASS

    package com.db.demo;
    
    
    import android.content.Context;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.provider.BaseColumns;
    
    /**
     * Subclass of the {@link SQLiteOpenHelper} that sets up the database for the
     * demo.
     * 
     * @author Kah
     */
    public class DatabaseHelper extends SQLiteOpenHelper {
    
    public DatabaseHelper(Context context) {
        super(context, "CursorDemo", null, 1);
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE IF NOT EXISTS names ("
                + BaseColumns._ID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, first VARCHAR, last VARCHAR)");
        db.execSQL("INSERT INTO names (first, last) VALUES ('John', 'Doe')");
        db.execSQL("INSERT INTO names (first, last) VALUES ('James', 'Kirk')");
    }
    
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Steps to upgrade the database for the new version ...
    }
    

    }

    ****Activity class****

    package com.db.demo;
    
    
    import android.app.ListActivity;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.provider.BaseColumns;
    import android.widget.CursorAdapter;
    import android.widget.ListView;
    import android.widget.SimpleCursorAdapter;
    
    public class DataHandlingActivity extends ListActivity{
        private SQLiteDatabase database;
     String fields[] = { "first", "last", BaseColumns._ID };
        private CursorAdapter dataSource;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DatabaseHelper helper = new DatabaseHelper(this);
        database = helper.getReadableDatabase();
        Cursor data = database.query("names", fields, null, null, null, null,
                null);
    
        dataSource = new SimpleCursorAdapter(this, R.layout.row, data, fields,
                new int[] { R.id.first, R.id.last });
    
        ListView view = getListView();
        view.setHeaderDividersEnabled(true);
        view.addHeaderView(getLayoutInflater().inflate(R.layout.row, null));
    
        setListAdapter(dataSource);
    }
    

    }

    use something like this in button click and change activity class
    update sql database with ContentValues and the update-method

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

Sidebar

Related Questions

I have an android app that wants to initiate an email. The following code
The application will run fine unless I add the following code. public class TFView
I know that eclipse can do this, can Intellij via the new Android support
I am using following code to open Android Contacts @Override public void onCreate(Bundle savedInstanceState)
I'm using the following code in an application of mine, and it's always used
In my Android application, I am using spinner, and I have loaded data from
The new Android 2.1 SDK (version 7) has a new class called SignalStrength: http://developer.android.com/reference/android/telephony/SignalStrength.html
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
I'm new to Android dev. There's a very pretty state diagram of the MediaPlayer
I'm new to Android and I think I'm trying to do something really basic:

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.