0

im just learning android programming and try following example from some tutorial to make sqlite

databasehelper.java
package simpleform.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

private static final String DATABASE_NAME = "studentdb";
private static final int DATABASE_VERSION = 1;

public static final String TABEL_STUDENT = "student";

public static final String ID            = "id";
public static final String NAME          = "name";
public static final String ADDRESS= "address";
public static final String BIRTH = "birth";

public static final String CREATE_TABEL_STUDENT = "CREATE TABLE "
        + TABEL_STUDENT + "(" + ID + " INTEGER PRIMARY KEY, "
        + NAME+ " TEXT, " + ADDRESS+ " TEXT, "
        + BIRTH + " DATE" + ")";

private static DataBaseHelper instance;

public static synchronized DataBaseHelper getHelper(Context context) {
    if (instance == null)
        instance = new DataBaseHelper(context);
    return instance;
}

private DataBaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(CREATE_TABEL_STUDENT);
}

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

When I am trying to run it on Android virtual Device , It says unfortunately , sqLite has stopped

bangtuts
  • 13
  • 2
  • 1
    post the error log – Kaushal28 May 19 '17 at 16:37
  • in andoid studio and emulator no log error, just message sqlite has been stopped, tried at xiaomi device here is the summary: va.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.khoerul.simpleemployee/com.example.khoerul.simpleemployee.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setTitle(int)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2449) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2509) – bangtuts May 19 '17 at 17:16
  • There are multiple typo of TABEL_STUDENT in your code. Shouldn't it be TABLE_STUDENT? And judging from your error log, it seems you cannot start DB in your MainActivity, which causes NPE. You should post it too. – Hasan Saykın May 19 '17 at 17:24
  • should have post the real code, kindly look at the answer below sir, thank you... – bangtuts May 19 '17 at 17:37
  • Possible duplicate of [Android Error \[Attempt to invoke virtual method 'void android.app.ActionBar' on a null object reference\]](http://stackoverflow.com/questions/28144657/android-error-attempt-to-invoke-virtual-method-void-android-app-actionbar-on) – petey May 19 '17 at 17:51
  • Possible duplicate of [Android FragmentActivity returns null in getActionBar()](http://stackoverflow.com/questions/29581396/android-fragmentactivity-returns-null-in-getactionbar) – Sammy T May 19 '17 at 19:42

1 Answers1

0

Have you tried?

  protected void setFragmentTitle(int resourseId) {
        setTitle(resourseId);
        getSupportActionBar().setTitle(resourseId); 
    }

As pointed out by petey.

Hasan Saykın
  • 138
  • 1
  • 8