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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:40:35+00:00 2026-06-05T04:40:35+00:00

i’m ready to develop my second app for android, and I want to use

  • 0

i’m ready to develop my second app for android, and I want to use the database. But I’m blocked by an error.

This is the class:

public class MyDatabase {  

    SQLiteDatabase mDb;
    DbHelper mDbHelper;
    Context mContext;
    private static final String DB_NAME="epsoftsms";//nome del db
    private static final int DB_VERSION=1; //numero di versione del nostro db

    public MyDatabase(Context ctx){
            mContext=ctx;
            mDbHelper=new DbHelper(ctx, DB_NAME, null, DB_VERSION);   //quando istanziamo questa classe, istanziamo anche l'helper (vedi sotto)    
    }

    public void open(){  //il database su cui agiamo è leggibile/scrivibile


        mDb=mDbHelper.getWritableDatabase();

    }

    public void close(){ //chiudiamo il database su cui agiamo
            mDb.close();
    }


    //i seguenti 2 metodi servono per la lettura/scrittura del db. aggiungete e modificate a discrezione
   // consiglio:si potrebbe creare una classe Prodotto, i quali oggetti verrebbero passati come parametri dei seguenti metodi, rispettivamente ritornati. Lacio a voi il divertimento


    public void inserimentoParametri(String parametro,String valore){ //metodo per inserire i dati
            ContentValues cv=new ContentValues();
            cv.put(ParametriMetaData.PARAMETRO, parametro);
            cv.put(ParametriMetaData.VALORE, valore);
            mDb.insert(ParametriMetaData.TAB_PARAMETRI, null, cv);
    }

    public Cursor listaParametri(){ //metodo per fare la query di tutti i dati



        return mDb.query(ParametriMetaData.TAB_PARAMETRI, null,null,null,null,null,null);



    }

    static class ParametriMetaData {  // i metadati della tabella, accessibili ovunque
            static final String TAB_PARAMETRI = "parametri";
            static final String PARAMETRO = "_parametro";
            static final String VALORE = "valore";

    }

    private static final String CREA_TAB_PARAMETRI = "CREATE TABLE IF NOT EXISTS "  //codice sql di creazione della tabella
                    + ParametriMetaData.TAB_PARAMETRI + " ("
                    + ParametriMetaData.PARAMETRO+ " text primary key, "
                    + ParametriMetaData.VALORE + " text not null);";

    private class DbHelper extends SQLiteOpenHelper { //classe che ci aiuta nella creazione del db

            public DbHelper(Context context, String name, CursorFactory factory,int version) {
                    super(context, name, factory, version);
            }

            public SQLiteDatabase getWritableDatabase() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public void onCreate(SQLiteDatabase _db) { //solo quando il db viene creato, creiamo la tabella
                    _db.execSQL(CREA_TAB_PARAMETRI);
            }

            @Override
            public void onUpgrade(SQLiteDatabase _db, int oldVersion, int newVersion) {
                    //qui mettiamo eventuali modifiche al db, se nella nostra nuova versione della app, il db cambia numero di versione

            }

    }


}

And this is part of main interested:

   final MyDatabase db=new MyDatabase(getApplicationContext());
    db.open();  //apriamo il db



    if (db.listaParametri().getCount()==0)
    {


   }

When I launch the app it return the following errors:

06-08 14:04:40.197: E/AndroidRuntime(1149): Uncaught handler: thread main exiting due to uncaught exception
06-08 14:04:40.207: E/AndroidRuntime(1149): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.axiomatic.epsoft.sms/it.axiomatic.epsoft.sms.EpsoftSMSActivity}: java.lang.NullPointerException
06-08 14:04:40.207: E/AndroidRuntime(1149):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at android.os.Looper.loop(Looper.java:123)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at android.app.ActivityThread.main(ActivityThread.java:3948)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at java.lang.reflect.Method.invokeNative(Native Method)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at java.lang.reflect.Method.invoke(Method.java:521)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at dalvik.system.NativeStart.main(Native Method)
06-08 14:04:40.207: E/AndroidRuntime(1149): Caused by: java.lang.NullPointerException
06-08 14:04:40.207: E/AndroidRuntime(1149):     at it.axiomatic.epsoft.sms.MyDatabase.listaParametri(MyDatabase.java:50)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at it.axiomatic.epsoft.sms.EpsoftSMSActivity.onCreate(EpsoftSMSActivity.java:30)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
06-08 14:04:40.207: E/AndroidRuntime(1149):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
06-08 14:04:40.207: E/AndroidRuntime(1149):     ... 11 more

What’s the problem? Tnx and forgive me for some error, it’s my first requesto on Stackoverflow.

  • 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-05T04:40:38+00:00Added an answer on June 5, 2026 at 4:40 am

    This is your problem:

            public SQLiteDatabase getWritableDatabase() { 
                // TODO Auto-generated method stub 
                return null; 
            } 
    

    You are overriding the SQLiteDatabase class getWritableDatabase method and doing nothing in it (not opening the database or anything) and returning null, so that leads to an NPE.

    Delete that method and your NPE should go away.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.