• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps SQLite not working

AQSAANUM

Member
Jun 1, 2017
55
13
Hey,
I have two activities one is Database helper and other is main activity. There is no sytax error but whenever I press Accept button (accButton), my app stops working.
Please help me out thanks.

DBHelper class:


Java:
package com.example.anum.lmslite;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;


public class sqliteDbHelper extends SQLiteOpenHelper {

    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "LMSLiteDB.db";
    public static final String TABLE_NAME = "LMSLiteDB";
    public static final String COLUMN_ID = "ID";
    public static final String COLUMN_PASSWORD = "Password";
    public static final String COLUMN_Name = "Name";
    public static final String COLUMN_VUEmail = "VU-Email";
    public static final String COLUMN_CITY = "City";
    public static final String COLUMN_COUNTRY = "Country";
    public static final String COLUMN_SELECTEDCOURSE = "Selected_Course";



    //constructor for SQLiteDBHelper class
    public sqliteDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION); //four perameters factory is null

    }

    //implementing and overriding two methods of SQLiteDatabaseOpenHelper class
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table" + TABLE_NAME + "create table LMSLiteDB(ID text primary key not null," +
                "Password text not null, Name text not null, VU-Email text not null, City text not null," +
                "Country text not null, Selected_Course text not null);");

    }

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


        db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME);
        onCreate(db);
    }

    public boolean insertValues(String id, String autoPass, String name, String mail, String city, String contry , String selectedCourse) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(COLUMN_ID, id);
        values.put(COLUMN_PASSWORD, autoPass);
        values.put(COLUMN_Name, name);
        values.put(COLUMN_VUEmail, mail);
        values.put(COLUMN_CITY, city);
        values.put(COLUMN_COUNTRY, contry);
        values.put(COLUMN_SELECTEDCOURSE, selectedCourse);

        long result = db.insert(TABLE_NAME, null, values);
        if (result == -1)
            return false;
        else
            return true;
    }


    /*public String searchinf(String id) {
        db = this.getReadableDatabase();
        String query = "select ID , Password from" + TABLE_NAME;

        Cursor cursor = db.rawQuery(query, null);
        String dbName, dbPassword;
        dbPassword = "Password not found";

        dbName = cursor.getString(0);
        if (dbName.equals(id)) {
            dbPassword = cursor.getString(1);
        } else{
            return dbPassword; }
        return dbPassword;

    }*/
}


And this is Main activity class:

Java:
  sqliteDbHelper db = new sqliteDbHelper(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_accept);

        String fName = getIntent().getStringExtra("fName");
        TextView tfName = (TextView)findViewById(R.id.fName);
        tfName.setText(fName);
        String vuEmail = getIntent().getStringExtra("vuEmail");
        TextView tEmail = (TextView)findViewById(R.id.vuEmail);
        tEmail.setText(vuEmail);
        String id = getIntent().getStringExtra("id");
        TextView tId = (TextView)findViewById(R.id.id);
        tId.setText(id);
        String password = getIntent().getStringExtra("password");
        TextView tPassword = (TextView)findViewById(R.id.password);
        tPassword.setText(password);
        String city = getIntent().getStringExtra("city");
        TextView tCity = (TextView)findViewById(R.id.city);
        tCity.setText(city);
        String contry = getIntent().getStringExtra("contry");
        TextView tContry = (TextView)findViewById(R.id.contry);
        tContry.setText(contry);
        String item = getIntent().getStringExtra("item");
        TextView tItem = (TextView)findViewById(R.id.item);
        tItem.setText(item);


    }


    public void onAccClick(View view) {

        TextView tfName = (TextView) findViewById(R.id.fName);
        TextView tEmail = (TextView) findViewById(R.id.vuEmail);
        TextView tId = (TextView) findViewById(R.id.id);
        TextView tPassword = (TextView) findViewById(R.id.password);
        TextView tCity = (TextView) findViewById(R.id.city);
        TextView tContry = (TextView) findViewById(R.id.contry);
        TextView tItem = (TextView) findViewById(R.id.item);


        boolean isInserted = db.insertValues(tId.getText().toString(), tPassword.getText().toString(), tfName.getText().toString(),
                tEmail.getText().toString(), tCity.getText().toString(), tContry.getText().toString(),
                tItem.getText().toString());
        if (isInserted = true) {
            Toast.makeText(ACCEPT.this, "Data Inserted", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(ACCEPT.this, "Data not Inserted", Toast.LENGTH_LONG).show();
        }
    }
 
Hey,
I have two activities one is Database helper and other is main activity. There is no sytax error but whenever I press Accept button (accButton), my app stops working.
Please help me out thanks.

DBHelper class:


Java:
package com.example.anum.lmslite;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;


public class sqliteDbHelper extends SQLiteOpenHelper {

    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "LMSLiteDB.db";
    public static final String TABLE_NAME = "LMSLiteDB";
    public static final String COLUMN_ID = "ID";
    public static final String COLUMN_PASSWORD = "Password";
    public static final String COLUMN_Name = "Name";
    public static final String COLUMN_VUEmail = "VU-Email";
    public static final String COLUMN_CITY = "City";
    public static final String COLUMN_COUNTRY = "Country";
    public static final String COLUMN_SELECTEDCOURSE = "Selected_Course";



    //constructor for SQLiteDBHelper class
    public sqliteDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION); //four perameters factory is null

    }

    //implementing and overriding two methods of SQLiteDatabaseOpenHelper class
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table" + TABLE_NAME + "create table LMSLiteDB(ID text primary key not null," +
                "Password text not null, Name text not null, VU-Email text not null, City text not null," +
                "Country text not null, Selected_Course text not null);");

    }

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


        db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME);
        onCreate(db);
    }

    public boolean insertValues(String id, String autoPass, String name, String mail, String city, String contry , String selectedCourse) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(COLUMN_ID, id);
        values.put(COLUMN_PASSWORD, autoPass);
        values.put(COLUMN_Name, name);
        values.put(COLUMN_VUEmail, mail);
        values.put(COLUMN_CITY, city);
        values.put(COLUMN_COUNTRY, contry);
        values.put(COLUMN_SELECTEDCOURSE, selectedCourse);

        long result = db.insert(TABLE_NAME, null, values);
        if (result == -1)
            return false;
        else
            return true;
    }


    /*public String searchinf(String id) {
        db = this.getReadableDatabase();
        String query = "select ID , Password from" + TABLE_NAME;

        Cursor cursor = db.rawQuery(query, null);
        String dbName, dbPassword;
        dbPassword = "Password not found";

        dbName = cursor.getString(0);
        if (dbName.equals(id)) {
            dbPassword = cursor.getString(1);
        } else{
            return dbPassword; }
        return dbPassword;

    }*/
}


And this is Main activity class:

Java:
  sqliteDbHelper db = new sqliteDbHelper(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_accept);

        String fName = getIntent().getStringExtra("fName");
        TextView tfName = (TextView)findViewById(R.id.fName);
        tfName.setText(fName);
        String vuEmail = getIntent().getStringExtra("vuEmail");
        TextView tEmail = (TextView)findViewById(R.id.vuEmail);
        tEmail.setText(vuEmail);
        String id = getIntent().getStringExtra("id");
        TextView tId = (TextView)findViewById(R.id.id);
        tId.setText(id);
        String password = getIntent().getStringExtra("password");
        TextView tPassword = (TextView)findViewById(R.id.password);
        tPassword.setText(password);
        String city = getIntent().getStringExtra("city");
        TextView tCity = (TextView)findViewById(R.id.city);
        tCity.setText(city);
        String contry = getIntent().getStringExtra("contry");
        TextView tContry = (TextView)findViewById(R.id.contry);
        tContry.setText(contry);
        String item = getIntent().getStringExtra("item");
        TextView tItem = (TextView)findViewById(R.id.item);
        tItem.setText(item);


    }


    public void onAccClick(View view) {

        TextView tfName = (TextView) findViewById(R.id.fName);
        TextView tEmail = (TextView) findViewById(R.id.vuEmail);
        TextView tId = (TextView) findViewById(R.id.id);
        TextView tPassword = (TextView) findViewById(R.id.password);
        TextView tCity = (TextView) findViewById(R.id.city);
        TextView tContry = (TextView) findViewById(R.id.contry);
        TextView tItem = (TextView) findViewById(R.id.item);


        boolean isInserted = db.insertValues(tId.getText().toString(), tPassword.getText().toString(), tfName.getText().toString(),
                tEmail.getText().toString(), tCity.getText().toString(), tContry.getText().toString(),
                tItem.getText().toString());
        if (isInserted = true) {
            Toast.makeText(ACCEPT.this, "Data Inserted", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(ACCEPT.this, "Data not Inserted", Toast.LENGTH_LONG).show();
        }
    }

https://www.sqlite.org/download.html
 
Upvote 0
Don't know there is too much in logcat.
I saw my data folder is also empty in Android device monitor.

If your app crashed when you clicked a button, then there will be a stack trace in the Logcat view, and we really need to see it, to offer any advice. Do you know what the stack trace looks like? It will be generated as soon as your app crashed. Just paste that bit of the log here and it should give us more information to work with.
 
Upvote 0
If your app crashed when you clicked a button, then there will be a stack trace in the Logcat view, and we really need to see it, to offer any advice. Do you know what the stack trace looks like? It will be generated as soon as your app crashed. Just paste that bit of the log here and it should give us more information to work with.
9 14:07:53.868 13616-13616/com.example.anum.lmslite V/InputMethodManager: Not IME target window, ignoring
07-19 14:07:53.931 13616-13616/com.example.anum.lmslite D/libEGL: loaded /system/lib/egl/libEGL_mali.so
07-19 14:07:53.933 13616-13616/com.example.anum.lmslite D/libEGL: loaded /system/lib/egl/libGLESv1_CM_mali.so
07-19 14:07:53.936 13616-13616/com.example.anum.lmslite D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so
07-19 14:07:53.947 13616-13616/com.example.anum.lmslite D/OpenGLRenderer: Enabling debug mode 0
07-19 14:07:54.117 13616-13616/com.example.anum.lmslite V/InputMethodManager: onWindowFocus: android.support.v7.widget.AppCompatEditText{4190b090 VFED..CL .F....I. 37,463-442,508 #7f0d0078 app:id/contry} softInputMode=272 first=true flags=#1810100
07-19 14:07:54.129 13616-13616/com.example.anum.lmslite V/InputMethodManager: START INPUT: android.support.v7.widget.AppCompatEditText{4190b090 VFED..CL .F....I. 37,463-442,508 #7f0d0078 app:id/contry} ic=com.android.internal.widget.EditableInputConnection@432dcd38 tba=android.view.inputmethod.EditorInfo@432dc910 controlFlags=#107
07-19 14:07:54.140 13616-13616/com.example.anum.lmslite V/InputMethodManager: Starting input: Bind result=InputBindResult{null com.android.inputmethod.latin/.LatinIME #9296}
07-19 14:07:54.210 13616-13623/com.example.anum.lmslite D/jdwp: processIncoming
07-19 14:07:54.210 13616-13623/com.example.anum.lmslite D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x40000018, flags=0x0, dataLen=0x9
07-19 14:07:54.210 13616-13623/com.example.anum.lmslite D/jdwp: sendBufferedRequest : len=0x34
07-19 14:07:54.227 13616-13616/com.example.anum.lmslite I/InputMethodManager: handleMessage: MSG_SET_ACTIVE true, was false
07-19 14:07:54.612 13616-13623/com.example.anum.lmslite D/jdwp: processIncoming
07-19 14:07:54.612 13616-13623/com.example.anum.lmslite D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x40000019, flags=0x0, dataLen=0x9
07-19 14:07:54.613 13616-13623/com.example.anum.lmslite D/jdwp: sendBufferedRequest : len=0x34
07-19 14:07:55.114 13616-13623/com.example.anum.lmslite D/jdwp: processIncoming
07-19 14:07:55.114 13616-13623/com.example.anum.lmslite D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000001A, flags=0x0, dataLen=0x9
07-19 14:07:55.114 13616-13623/com.example.anum.lmslite D/jdwp: sendBufferedRequest : len=0x34
07-19 14:07:55.116 13616-13623/com.example.anum.lmslite D/jdwp: processIncoming
07-19 14:07:55.116 13616-13623/com.example.anum.lmslite D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000001B, flags=0x0, dataLen=0x9
07-19 14:07:55.116 13616-13623/com.example.anum.lmslite D/jdwp: sendBufferedRequest : len=0x34
07-19 14:07:55.149 13616-13644/com.example.anum.lmslite I/SurfaceTextureClient: [STC::queueBuffer] (this:0x52751260) fps:29.55, dur:1015.33, max:256.49, min:7.13
07-19 14:07:55.617 13616-13623/com.example.anum.lmslite D/jdwp: processIncoming
07-19 14:07:55.617 13616-13623/com.example.anum.lmslite D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000001C, flags=0x0, dataLen=0x9
07-19 14:07:55.617 13616-13623/com.example.anum.lmslite D/jdwp: sendBufferedRequest : len=0x34
07-19 14:07:56.118 13616-13623/com.example.anum.lmslite D/jdwp: processIncoming
07-19 14:07:56.118 13616-13623/com.example.anum.lmslite D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000001D, flags=0x0, dataLen=0x9
07-19 14:07:56.118 13616-13623/com.example.anum.lmslite D/jdwp: sendBufferedRequest : len=0x34
07-19 14:07:56.149 13616-13644/com.example.anum.lmslite I/SurfaceTextureClient: [STC::queueBuffer] (this:0x52751260) fps:2.00, dur:1000.06, max:512.08, min:487.99
07-19 14:07:56.620 13616-13623/com.example.anum.lmslite D/jdwp: processIncoming
07-19 14:07:56.620 13616-13623/com.example.anum.lmslite D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000001E, flags=0x0, dataLen=0x9
07-19 14:07:56.620 13616-13623/com.example.anum.lmslite D/jdwp: sendBufferedRequest : len=0x34
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones