Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite database is not getting created..Why?
    primarykey
    data
    text
    <p>I was trying to add the data i receive from some specific messages to SQLite database.. But when i run my application i am getting error which says ... Fatal Exception : Main caused by Java Null Pointer exception at the InsertTitle Function in my DBAdapter.java</p> <p>This is my DBAdapter Class</p> <pre><code>package com.lalsoft.janko; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DBAdapter { public static final String KEY_ROWID = "_id"; public static final String KEY_GQTY = "gqty"; public static final String KEY_NQTY = "nqty"; public static final String KEY_DATE = "ddate"; private static final String TAG = "DBAdapter"; private static final String DATABASE_NAME = "lalaqua"; private static final String DATABASE_TABLE = "nsales"; private static final int DATABASE_VERSION = 1; private static final String DATABASE_CREATE = "create table titles (_id integer primary key autoincrement, " + "gqty text not null, nqty text not null, " + "ddate text not null);"; private final Context context; private DatabaseHelper DBHelper; private SQLiteDatabase db; public DBAdapter(Context ctx) { this.context = ctx; DBHelper = new DatabaseHelper(context); } private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS titles"); onCreate(db); } } //---opens the database--- public DBAdapter open() throws SQLException { db = DBHelper.getWritableDatabase(); return this; } //---closes the database--- public void close() { DBHelper.close(); } //---insert a title into the database--- public long insertTitle(String gqty, String nqty, String ddate) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_GQTY, gqty); initialValues.put(KEY_NQTY, nqty); initialValues.put(KEY_DATE, ddate); return db.insert(DATABASE_TABLE, null, initialValues); } //---deletes a particular title--- public boolean deleteTitle(long rowId) { return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) &gt; 0; } //---retrieves all the titles--- public Cursor getAllTitles() { return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_GQTY, KEY_NQTY, KEY_DATE}, null, null, null, null, null); } //---retrieves a particular title--- public Cursor getTitle(long rowId) throws SQLException { Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] { KEY_ROWID, KEY_GQTY, KEY_NQTY, KEY_DATE }, KEY_ROWID + "=" + rowId, null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; } //---updates a title--- public boolean updateTitle(long rowId, String gqtr, String nqty, String ddate) { ContentValues args = new ContentValues(); args.put(KEY_GQTY, gqtr); args.put(KEY_NQTY, nqty); args.put(KEY_DATE, ddate); return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) &gt; 0; } } </code></pre> <p>This is the class which extends from BroadcastReceiver, which is calling the inserttitle function..</p> <pre><code>package com.lalsoft.janko; import java.util.Calendar; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.gsm.SmsManager; import android.telephony.gsm.SmsMessage; import android.util.Log; public class SMSReceiver extends BroadcastReceiver { public String SendMsgBody; private static final String LOG_TAG = "JankoSMS"; public DBAdapter db; public Integer isDone=0; public Double GrossQty,NetQty; @Override public void onReceive(Context context, Intent intent) { db = new DBAdapter(context); //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; String PhNo; String MsgBody; if (bundle != null) { //---retrieve the SMS message received--- Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i=0; i&lt;msgs.length; i++){ msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); str += "SMS from " + msgs[i].getOriginatingAddress(); PhNo=msgs[i].getOriginatingAddress(); str += " :"; str += msgs[i].getMessageBody().toString(); MsgBody=msgs[i].getMessageBody().toString(); str += "\n"; // EncodeSMS(MsgBody); String GQtyS,NQtyS,sDate; GQtyS="Ok"; NQtyS="Done"; sDate=getDate(); Log.i(LOG_TAG, "Date" +" "+ sDate +" "+ GQtyS +" "+ NQtyS); long id; id = db.insertTitle(GQtyS ,NQtyS,sDate); } } } public static String getDate() { Calendar c = Calendar.getInstance(); String sDate = c.get(Calendar.DAY_OF_MONTH) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.YEAR); //+ " at " + c.get(Calendar.HOUR_OF_DAY) //+ ":" + c.get(Calendar.MINUTE); return sDate; } } </code></pre> <p>Also i have checked the database is not getting created.. So what should be the possible cause of this issue and how can i solve this?? Please help me out of this trouble.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload