1. Are you ready for the Galaxy S20? Here is everything we know so far!

SQLite not working

Discussion in 'Android Development' started by AQSAANUM, Jul 18, 2017.

  1. AQSAANUM

    AQSAANUM Member
    Thread Starter

    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:


    Code (Java):
    1. package com.example.anum.lmslite;
    2.  
    3. import android.content.ContentValues;
    4. import android.content.Context;
    5. import android.database.Cursor;
    6. import android.database.sqlite.SQLiteDatabase;
    7. import android.database.sqlite.SQLiteOpenHelper;
    8. import android.widget.Toast;
    9.  
    10.  
    11. public class sqliteDbHelper extends SQLiteOpenHelper {
    12.  
    13.     public static final int DATABASE_VERSION = 1;
    14.     public static final String DATABASE_NAME = "LMSLiteDB.db";
    15.     public static final String TABLE_NAME = "LMSLiteDB";
    16.     public static final String COLUMN_ID = "ID";
    17.     public static final String COLUMN_PASSWORD = "Password";
    18.     public static final String COLUMN_Name = "Name";
    19.     public static final String COLUMN_VUEmail = "VU-Email";
    20.     public static final String COLUMN_CITY = "City";
    21.     public static final String COLUMN_COUNTRY = "Country";
    22.     public static final String COLUMN_SELECTEDCOURSE = "Selected_Course";
    23.  
    24.  
    25.  
    26.     //constructor for SQLiteDBHelper class
    27.     public sqliteDbHelper(Context context) {
    28.         super(context, DATABASE_NAME, null, DATABASE_VERSION); //four perameters factory is null
    29.  
    30.     }
    31.  
    32.     //implementing and overriding two methods of SQLiteDatabaseOpenHelper class
    33.     @Override
    34.     public void onCreate(SQLiteDatabase db) {
    35.         db.execSQL("create table" + TABLE_NAME + "create table LMSLiteDB(ID text primary key not null," +
    36.                 "Password text not null, Name text not null, VU-Email text not null, City text not null," +
    37.                 "Country text not null, Selected_Course text not null);");
    38.  
    39.     }
    40.  
    41.     @Override
    42.     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    43.  
    44.  
    45.         db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME);
    46.         onCreate(db);
    47.     }
    48.  
    49.     public boolean insertValues(String id, String autoPass, String name, String mail, String city, String contry , String selectedCourse) {
    50.         SQLiteDatabase db = this.getWritableDatabase();
    51.         ContentValues values = new ContentValues();
    52.         values.put(COLUMN_ID, id);
    53.         values.put(COLUMN_PASSWORD, autoPass);
    54.         values.put(COLUMN_Name, name);
    55.         values.put(COLUMN_VUEmail, mail);
    56.         values.put(COLUMN_CITY, city);
    57.         values.put(COLUMN_COUNTRY, contry);
    58.         values.put(COLUMN_SELECTEDCOURSE, selectedCourse);
    59.  
    60.         long result = db.insert(TABLE_NAME, null, values);
    61.         if (result == -1)
    62.             return false;
    63.         else
    64.             return true;
    65.     }
    66.  
    67.  
    68.     /*public String searchinf(String id) {
    69.         db = this.getReadableDatabase();
    70.         String query = "select ID , Password from" + TABLE_NAME;
    71.  
    72.         Cursor cursor = db.rawQuery(query, null);
    73.         String dbName, dbPassword;
    74.         dbPassword = "Password not found";
    75.  
    76.         dbName = cursor.getString(0);
    77.         if (dbName.equals(id)) {
    78.             dbPassword = cursor.getString(1);
    79.         } else{
    80.             return dbPassword; }
    81.         return dbPassword;
    82.  
    83.     }*/
    84. }

    And this is Main activity class:

    Code (Java):
    1.   sqliteDbHelper db = new sqliteDbHelper(this);
    2.     @Override
    3.     protected void onCreate(Bundle savedInstanceState) {
    4.         super.onCreate(savedInstanceState);
    5.         setContentView(R.layout.activity_accept);
    6.  
    7.         String fName = getIntent().getStringExtra("fName");
    8.         TextView tfName = (TextView)findViewById(R.id.fName);
    9.         tfName.setText(fName);
    10.         String vuEmail = getIntent().getStringExtra("vuEmail");
    11.         TextView tEmail = (TextView)findViewById(R.id.vuEmail);
    12.         tEmail.setText(vuEmail);
    13.         String id = getIntent().getStringExtra("id");
    14.         TextView tId = (TextView)findViewById(R.id.id);
    15.         tId.setText(id);
    16.         String password = getIntent().getStringExtra("password");
    17.         TextView tPassword = (TextView)findViewById(R.id.password);
    18.         tPassword.setText(password);
    19.         String city = getIntent().getStringExtra("city");
    20.         TextView tCity = (TextView)findViewById(R.id.city);
    21.         tCity.setText(city);
    22.         String contry = getIntent().getStringExtra("contry");
    23.         TextView tContry = (TextView)findViewById(R.id.contry);
    24.         tContry.setText(contry);
    25.         String item = getIntent().getStringExtra("item");
    26.         TextView tItem = (TextView)findViewById(R.id.item);
    27.         tItem.setText(item);
    28.  
    29.  
    30.     }
    31.  
    32.  
    33.     public void onAccClick(View view) {
    34.  
    35.         TextView tfName = (TextView) findViewById(R.id.fName);
    36.         TextView tEmail = (TextView) findViewById(R.id.vuEmail);
    37.         TextView tId = (TextView) findViewById(R.id.id);
    38.         TextView tPassword = (TextView) findViewById(R.id.password);
    39.         TextView tCity = (TextView) findViewById(R.id.city);
    40.         TextView tContry = (TextView) findViewById(R.id.contry);
    41.         TextView tItem = (TextView) findViewById(R.id.item);
    42.  
    43.  
    44.         boolean isInserted = db.insertValues(tId.getText().toString(), tPassword.getText().toString(), tfName.getText().toString(),
    45.                 tEmail.getText().toString(), tCity.getText().toString(), tContry.getText().toString(),
    46.                 tItem.getText().toString());
    47.         if (isInserted = true) {
    48.             Toast.makeText(ACCEPT.this, "Data Inserted", Toast.LENGTH_LONG).show();
    49.         } else {
    50.             Toast.makeText(ACCEPT.this, "Data not Inserted", Toast.LENGTH_LONG).show();
    51.         }
    52.     }
    53.  
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Deleted User

    Deleted User Guest

    You'll need to provide the stack trace from the Logcat view
     
  3. Phalon4

    Phalon4 Android Enthusiast

    https://www.sqlite.org/download.html
     
  4. AQSAANUM

    AQSAANUM Member
    Thread Starter

  5. AQSAANUM

    AQSAANUM Member
    Thread Starter

    Don't know there is too much in logcat.
    I saw my data folder is also empty in Android device monitor.
     
  6. Deleted User

    Deleted User Guest

    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.
     
  7. AQSAANUM

    AQSAANUM Member
    Thread Starter

    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
     
  8. Deleted User

    Deleted User Guest

  9. AQSAANUM

    AQSAANUM Member
    Thread Starter

  10. Deleted User

    Deleted User Guest

    I don't understand the question.
    If you can provide the stack trace, that will highlight the problem you are having.
     
  11. Phalon4

    Phalon4 Android Enthusiast

    I gave you a link where you may get some answers to your sqlite issues
    https://www.sqlite.org/doclist.html
     
  12. Deleted User

    Deleted User Guest

    At the risk of sounding like a broken record, there is no hope of answering the initial question of why this application crashed, without seeing the stack trace.
     
  13. AQSAANUM

    AQSAANUM Member
    Thread Starter

    Thanks for helping tip, I solved it :)
     
    sweetndreemy73 likes this.
Loading...
Similar Threads - SQLite working
  1. Castino
    Replies:
    1
    Views:
    430
  2. werner111
    Replies:
    6
    Views:
    1,835
  3. rowlanda38
    Replies:
    0
    Views:
    484
  4. iliji
    Replies:
    1
    Views:
    1,571
  5. dplusk
    Replies:
    0
    Views:
    1,067
  6. selva_0707
    Replies:
    0
    Views:
    1,440
  7. manjula1
    Replies:
    0
    Views:
    726
  8. GabeTheGreat73
    Replies:
    0
    Views:
    578
  9. Dilip Birajadar
    Replies:
    4
    Views:
    889
  10. Negrazo1949
    Replies:
    3
    Views:
    1,063

Share This Page

Loading...