Regardless of what I appear to perform in regards to this listview and looking to get it to dynamically update whenever I hit a control button it does not work and try to throws a NPE.

The code is below and that i would actually welcome an assistance. I have attempted requery and I have attempted notifyDataSetChanged, but I'm going to be honest, this really is only my second project and also the first one that's utilizing a database or listview and I'll battling.


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; 
import android.provider.BaseColumns;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {

private static final String TAG = DatabaseHelper.class.getSimpleName();

public static final String DATABASE_NAME = "reordermymeds.db";
public static final int DATABASE_VERSION = 3;
public static final String TABLE_NAME = "Medicines";
public static final String C_ID = BaseColumns._ID;
public static final String C_MED_NAME = "med_name"; 
public static final String TABLE_NAME_SURG = "Surgeries";
public static final String SURGERY_NAME = "sName";
public static final String SURGERY_TEL = "sTel";
public static final String SURGERY_MAIL = "sMail";

public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    // TODO Auto-generated constructor stub

public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    String sql = String.format("CREATE TABLE %s (%s INTEGER PRIMARY KEY, %s     TEXT)", TABLE_NAME, C_ID, C_MED_NAME);
    String sql_surg = String.format(
            "create table %s (%s int primary key, %s TEXT, %s TEXT, %s TEXT)", 

    Log.d(TAG, "onCreate sql: "+sql);



public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
    db.execSQL("drop table if exists " + TABLE_NAME);
    db.execSQL("drop table if exists " + TABLE_NAME_SURG);




import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class pills extends ListActivity {

public static final String C_MED_NAME = "med_name";
public SimpleCursorAdapter ladapter;

public void onCreate(Bundle savedInstanceState) {

    try {

            DatabaseHelper DBHelper= new DatabaseHelper(this);
            SQLiteDatabase db = DBHelper.getReadableDatabase();

            Cursor cur = db.query("Medicines", null, null, null, null, null, null);

            String [] columns = new String[] {C_MED_NAME};
            int [] to = new int[] {};

            SimpleCursorAdapter ladapter = new SimpleCursorAdapter(this, R.layout.meditem, cur, columns, to);

    } catch (Exception e) {
        // TODO Auto-generated catch block

    Button saveMed = (Button) findViewById(;
    saveMed.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            final EditText newMed = (EditText) findViewById(;

            if (newMed.getText().toString().equals("")) {

                    Context context = getApplicationContext();
                    CharSequence text = "Please type the name of a new prescription item.";
                    int duration = Toast.LENGTH_SHORT;

                    Toast toast= Toast.makeText(context, text, duration);

                    String medName = newMed.getText().toString();


                    EditText clearTextBox = (EditText) findViewById(;

                    Context context = getApplicationContext();
                    CharSequence text = "Saved";
                    int duration = Toast.LENGTH_SHORT;

                    Toast toast = Toast.makeText(context, text, duration);





    private void insertNewPrescriptionItem (String medName){

        DatabaseHelper DbHelper = new DatabaseHelper(this);

        SQLiteDatabase db = DbHelper.getWritableDatabase();

        ContentValues cv = new ContentValues();

            cv.put(DatabaseHelper.C_MED_NAME, medName);

            db.insert(DatabaseHelper.TABLE_NAME, DatabaseHelper.C_MED_NAME, cv);


not to mention, finally, the stack trace. I can tell the road using the error, but every I've attempted using Google just leads to exactly the same factor. Can anybody show were I have to go stupidly wrong??

Stack Trace

08-11 01:21:26.095: ERROR/AndroidRuntime(15327): FATAL EXCEPTION: main
08-11 01:21:26.095: ERROR/AndroidRuntime(15327): java.lang.NullPointerException
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at com.asurya.reordmymeds.pills$1.onClick(
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at android.view.View.performClick(
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at android.view.View$
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at android.os.Handler.handleCallback(
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at android.os.Handler.dispatchMessage(
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at android.os.Looper.loop(
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at java.lang.reflect.Method.invokeNative(Native Method)
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at java.lang.reflect.Method.invoke(
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at$
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at
08-11 01:21:26.095: ERROR/AndroidRuntime(15327):     at dalvik.system.NativeStart.main(Native Method)
08-11 01:21:26.107: WARN/ActivityManager(110):   Force finishing activity com.asurya.reordmymeds/.pills

Oops. It might have assisted basically allow you to are all aware that instead of count them her:)

The road of code that is leading to the NPE is:


Also, basically simply comment out this line, the application runs fine, but you need to refresh the game to determine the up-to-date data within the database. Thanks all.