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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:08:08+00:00 2026-05-23T03:08:08+00:00

I’m baffled by what is happening to my simple code. It just doesn’t go

  • 0

I’m baffled by what is happening to my simple code. It just doesn’t go into another class file even though I checked that code flows. Below is my code in android:

public class MedF1 extends ListActivity {

DrugsDbAdapter drugsDbAdapter = new DrugsDbAdapter(this);
DrugsDbAdapter.myDbHelper mDbHelper = new DrugsDbAdapter.myDbHelper(this);

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drug_list);



    try {

        mDbHelper.createDataBase();

        } catch (IOException ioe) {

        throw new Error("Unable to create database");

        }

        try {

        mDbHelper.openDataBase();

        }catch(SQLException sqle){

        throw sqle;

        }

        populateDrugList();

}

public void populateDrugList() {

    Cursor drugListCursor = drugsDbAdapter.getAllEntries();

    startManagingCursor (drugListCursor);

    String[] from = new String[] {DrugsDbAdapter.KEY_DRUG};

    int[] to = new int[] {R.id.text1};

    SimpleCursorAdapter drugs = new SimpleCursorAdapter(this, R.layout.drug_row, drugListCursor, from, to);

    setListAdapter(drugs);
}

The database adapter class is below , the code just doesn’t go beyond druglistCursor of the populateDrugList() in the above code!

public class DrugsDbAdapter {

private static final String DATABASE_TABLE = "data";


//The index column name for use in where clauses
public static final String KEY_ID = "_id";

//The name and column index of each column in DB
public static final String KEY_DRUG = "drug";
public static final String KEY_CONTENT = "content";
public static final String KEY_INDICATION = "indication";
public static final String KEY_DOSAGE = "dosage";
public static final String KEY_SPECIALPRECAUTION = "specialprecaution";


//variable to hold the database instance
private static SQLiteDatabase db;
//Context of the application using the database
private final Context context;
//Database open/upgrade helper
private myDbHelper dbHelper;

public DrugsDbAdapter(Context _context) {

    this.context = _context;

}

public void open() throws SQLiteException {
    try {
        db = dbHelper.getWritableDatabase();
    } catch (SQLiteException ex) {
        db = dbHelper.getReadableDatabase();
    }
}

//Creation of database and basic parameters
public static class myDbHelper extends SQLiteOpenHelper {

    private static String DB_PATH = "data/data/com.paad.MedF1/databases/";

    private static String DB_NAME = "data.sqlite";

    private SQLiteDatabase myDataBase;

    private Context myContext;

    public  myDbHelper (Context context) {

        super(context, DB_NAME, null, 1);

        this.myContext = context;

    }

    public void createDataBase() throws IOException{

        boolean dbExist = checkDataBase();

        if(dbExist) {
            // do nothing
        } else {

            this.getReadableDatabase();

            try {

                copyDataBase();

            } catch (IOException e) {

                throw new Error ("Error copying database");

            }

        }
    }

    private boolean checkDataBase(){


        boolean checkDB = false;

        try{
            String myPath = DB_PATH + DB_NAME;
            File dbfile = new File(myPath);

            checkDB = dbfile.exists();

        }catch(SQLiteException e){

            //database does't exist yet.

        }

        return checkDB;

    }


    private void copyDataBase() throws IOException{

        //Open your local db as the input stream
        InputStream myInput = myContext.getAssets().open(DB_NAME);

        // Path to the just created empty db
        String outFileName = DB_PATH + DB_NAME;

        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);

        //transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
            myOutput.write(buffer, 0, length);
        }

        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();

    }

    public void openDataBase() throws SQLException{

        //Open the database
        String myPath = DB_PATH + DB_NAME;
        myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

    }

    @Override
    public synchronized void close() {

            if(myDataBase != null)
                myDataBase.close();

            super.close();

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}


public void close() {
    db.close();
}

public long insertEntry(myDrug _myDrug) {

    ContentValues newDrugValues = new ContentValues();

    newDrugValues.put(KEY_DRUG, _myDrug.getDrug());
    newDrugValues.put(KEY_CONTENT, _myDrug.getContent());
    newDrugValues.put(KEY_INDICATION, _myDrug.getIndication());
    newDrugValues.put(KEY_DOSAGE, _myDrug.getDosage());
    newDrugValues.put(KEY_SPECIALPRECAUTION, _myDrug.getSpecialprecaution());

    return db.insert(DATABASE_TABLE, null, newDrugValues);
}

public boolean removeEntry (long _rowIndex) {
    return db.delete(DATABASE_TABLE, KEY_ID + "=" + _rowIndex, null) > 0;
}

public Cursor getAllEntries () { 
    return db.query(DATABASE_TABLE, new String[] {KEY_ID, KEY_DRUG, KEY_CONTENT, KEY_INDICATION, KEY_DOSAGE, KEY_SPECIALPRECAUTION}, null, null, null, null, null);
}


}   

HElp !!! my logcat output is:

06-03 22:29:01.636: ERROR/AndroidRuntime(1424): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.paad.MedF1/com.paad.MedF1.MedF1}: java.lang.NullPointerException
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at android.os.Looper.loop(Looper.java:123)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at java.lang.reflect.Method.invokeNative(Native Method)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at java.lang.reflect.Method.invoke(Method.java:521)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at dalvik.system.NativeStart.main(Native Method)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424): Caused by: java.lang.NullPointerException
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at com.paad.MedF1.MedF1.populateDrugList(MedF1.java:51)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at com.paad.MedF1.MedF1.onCreate(MedF1.java:45)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-03 22:29:01.636: ERROR/AndroidRuntime(1424):     ... 11 more
  • 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-23T03:08:08+00:00Added an answer on May 23, 2026 at 3:08 am

    Your drugsDbAdapter is null. You have only declared DrugsDbAdapter drugsDbAdapter;, but you need to instantiate it.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.