I'm trying to fetch the data from SQLite using cursor method , but log cat keep saying.
I also gone through little details but i'm not getting whats wrong with the code. It would be great pleasure if you guys point of my error's in codes.
"java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first/com.example.first.SqlView}: android.database.sqlite.SQLiteException: no such column: KEY_ROWID (code 1): , while compiling: SELECT KEY_ROWID, KEY_NAME, KEY_INTELLIGENCE FROM peopleTable"
Follwing are the code files along with logs of logcat
SqlLiteExample1 file
package com.example.first;
import com.example.first.R.dimen;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class SqlLiteExample1 extends Activity implements OnClickListener {
Button saveToDataBase,retriveFromDataBase;
public static final String TAG = "problem";
EditText etName=null,etIntelligence=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sqllite);
initializer();
}
private void initializer() {
// TODO Auto-generated method stub
etName = (EditText)findViewById(R.id.etNamesqlLite);
etIntelligence = (EditText)findViewById(R.id.etIntelligence);
saveToDataBase = (Button)findViewById(R.id.bUpdateDataBase);
retriveFromDataBase = (Button)findViewById(R.id.bRetriveDataBase);
saveToDataBase.setOnClickListener(this);
retriveFromDataBase.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bUpdateDataBase:
boolean didItWork= true;
try {
String Name = etName.getText().toString();
String Intelligence = etIntelligence.getText().toString();
Log.e(TAG, " Poblem is not in fetching data from editText");
IntelligentOtNot entry = new IntelligentOtNot(SqlLiteExample1.this);
entry.open();
Log.e(TAG, " Poblem is not in method open");
entry.update(Name ,Intelligence);
Log.e(TAG, " Poblem is not in method update");
entry.close();
}catch (Exception e) {
// TODO: handle exception
didItWork = false;
}finally {
if(didItWork){
Log.e(TAG, " Poblem is not in if clause");
Dialog d = new Dialog( this);
d.setTitle("Oh yeah");
TextView tv = new TextView(this);
tv.setText("Success");
//tv.setTextSize("dp", "25");
d.setContentView(tv);
d.show();
}
}
break;
case R.id.bRetriveDataBase:
Intent i = new Intent("com.example.first.SQLVIEW");
startActivity(i);
break;
}
}
}
SQLVIEW file
package com.example.first;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class SqlView extends Activity {
TextView tvInfoFromDataBase;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.viewsqllite);
tvInfoFromDataBase = (TextView)findViewById(R.id.tvSqlInfo);
IntelligentOtNot info = new IntelligentOtNot(this);
info.open();
String sqlData = info.getData();
info.close();
tvInfoFromDataBase.setText(sqlData);
}
}
file IntelligentOtNot
package com.example.first;
import java.util.Currency;
import android.R.string;
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.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class IntelligentOtNot {
public static final String KEY_ROWID = "Rid";
public static final String KEY_NAME = "persons_name";
public static final String KEY_INTELLIGENCE = "persons_intelligence";
private static final String DATABASE_NAME = "IntelligentOrNotDb";
private static final String DATABASE_TABLE = "peopleTable";
private static final int DATABASE_VERSION = 2;
public static final String TAG = "problem";
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDataBase;
private static class DbHelper extends SQLiteOpenHelper {
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
Log.e(TAG, " onCreate method of SQLite is called");
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
+ " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_NAME
+ " TEXT NOT NULL, " + KEY_INTELLIGENCE
+ " TEXT NOT NULL );");
Log.e(TAG, " Query Executed successfully");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}
}
public IntelligentOtNot(Context c) {
// TODO Auto-generated constructor stub
ourContext = c;
}
public IntelligentOtNot open() throws SQLException {
ourHelper = new DbHelper(ourContext);
ourDataBase = ourHelper.getWritableDatabase();
return this;
}
public IntelligentOtNot close() {
ourHelper.close();
return null;
}
public long update(String name, String intelligence) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(KEY_NAME, name);
cv.put(KEY_INTELLIGENCE, intelligence);
return ourDataBase.insert(DATABASE_TABLE, null, cv);
}
public String getData() {
// TODO Auto-generated method stub
String[] columns = { "KEY_ROWID", "KEY_NAME", "KEY_INTELLIGENCE" };
Cursor c = ourDataBase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_NAME);
int iIntelligence = c.getColumnIndex(KEY_INTELLIGENCE);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result = result + c.getString(iRow) + " " + c.getString(iName)
+ " " + c.getString(iIntelligence) + "\n";
}
return result;
}
}
LOGCAT:
10-30 00:58:56.902: W/ApplicationPackageManager(4199): getCSCPackageItemText()
10-30 00:58:56.902: I/PersonaManager(4199): getPersonaService() name persona_policy
10-30 00:58:57.132: E/MoreInfoHPW_ViewGroup(4199): Parent view is not a TextView
10-30 00:58:57.232: D/dalvikvm(4199): GC_FOR_ALLOC freed 94K, 37% free 17030K/26660K, paused 17ms, total 18ms
10-30 00:58:57.252: I/dalvikvm-heap(4199): Grow heap (frag case) to 32.260MB for 12582928-byte allocation
10-30 00:58:57.342: V/MediaPlayer-JNI(4199): native_setup
10-30 00:58:57.342: V/MediaPlayer(4199): constructor
10-30 00:58:57.342: V/MediaPlayer(4199): setListener
10-30 00:58:57.342: V/MediaPlayer-JNI(4199): setDataSourceFD: fd 54
10-30 00:58:57.342: V/MediaPlayer(4199): setDataSource(54, 104515, 3969752)
10-30 00:58:57.352: V/MediaPlayer(4199): message received msg=8, ext1=0, ext2=0
10-30 00:58:57.352: V/MediaPlayer(4199): notify(8, 0, 0) callback on disconnected mediaplayer
10-30 00:58:57.382: V/MediaPlayer(4199): setVideoSurfaceTexture
10-30 00:58:57.382: V/MediaPlayer(4199): prepare
10-30 00:58:57.392: V/MediaPlayer(4199): message received msg=200, ext1=973, ext2=0
10-30 00:58:57.392: W/MediaPlayer(4199): info/warning (973, 0)
10-30 00:58:57.392: V/MediaPlayer(4199): callback application
10-30 00:58:57.392: V/MediaPlayer(4199): back from callback
10-30 00:58:57.392: V/MediaPlayer(4199): message received msg=5, ext1=0, ext2=0
10-30 00:58:57.392: V/MediaPlayer(4199): New video size 0 x 0
10-30 00:58:57.392: V/MediaPlayer(4199): callback application
10-30 00:58:57.392: V/MediaPlayer(4199): back from callback
10-30 00:58:57.392: V/MediaPlayer(4199): message received msg=1, ext1=0, ext2=0
10-30 00:58:57.392: V/MediaPlayer(4199): prepared
10-30 00:58:57.392: V/MediaPlayer(4199): signal application thread
10-30 00:58:57.392: V/MediaPlayer(4199): callback application
10-30 00:58:57.392: V/MediaPlayer(4199): prepare complete - status=0
10-30 00:58:57.392: V/MediaPlayer(4199): back from callback
10-30 00:58:57.402: I/MediaPlayer(4199): Don't send intent. msg.arg1 = 0, msg.arg2 = 0
10-30 00:58:57.402: E/MediaPlayer(4199): Should have subtitle controller already set
10-30 00:58:57.422: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.442: I/Adreno-EGL(4199): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
10-30 00:58:57.442: I/Adreno-EGL(4199): OpenGL ES Shader Compiler Version: E031.24.00.08+13
10-30 00:58:57.442: I/Adreno-EGL(4199): Build Date: 03/28/14 Fri
10-30 00:58:57.442: I/Adreno-EGL(4199): Local Branch: 0328_AU200_patches
10-30 00:58:57.442: I/Adreno-EGL(4199): Remote Branch:
10-30 00:58:57.442: I/Adreno-EGL(4199): Local Patches:
10-30 00:58:57.442: I/Adreno-EGL(4199): Reconstruct Branch:
10-30 00:58:57.482: D/OpenGLRenderer(4199): Enabling debug mode 0
10-30 00:58:57.512: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.602: V/MediaPlayer-JNI(4199): release
10-30 00:58:57.602: V/MediaPlayer(4199): setListener
10-30 00:58:57.602: V/MediaPlayer(4199): disconnect
10-30 00:58:57.602: V/MediaPlayer(4199): destructor
10-30 00:58:57.602: V/MediaPlayer(4199): disconnect
10-30 00:58:57.622: W/ApplicationPackageManager(4199): getCSCPackageItemText()
10-30 00:58:57.632: E/MoreInfoHPW_ViewGroup(4199): Parent view is not a TextView
10-30 00:58:57.672: D/AbsListView(4199): Get MotionRecognitionManager
10-30 00:58:57.692: D/AbsListView(4199): onVisibilityChanged() is called, visibility : 4
10-30 00:58:57.692: D/AbsListView(4199): unregisterIRListener() is called
10-30 00:58:57.702: D/AbsListView(4199): onVisibilityChanged() is called, visibility : 0
10-30 00:58:57.702: D/AbsListView(4199): unregisterIRListener() is called
10-30 00:58:57.722: D/AbsListView(4199): unregisterIRListener() is called
10-30 00:58:57.752: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.762: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.762: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.762: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.762: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.772: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.772: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.772: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.782: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.782: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.782: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.782: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.792: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.792: D/AbsListView(4199): unregisterIRListener() is called
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.802: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.812: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.812: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.812: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:57.832: D/AbsListView(4199): unregisterIRListener() is called
10-30 00:58:57.852: D/AbsListView(4199): unregisterIRListener() is called
10-30 00:58:59.342: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:58:59.352: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:59:00.492: D/AbsListView(4199): unregisterIRListener() is called
10-30 00:59:00.492: W/ApplicationPackageManager(4199): getCSCPackageItemText()
10-30 00:59:00.512: E/MoreInfoHPW_ViewGroup(4199): Parent view is not a TextView
10-30 00:59:00.572: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:59:01.012: D/AbsListView(4199): onVisibilityChanged() is called, visibility : 4
10-30 00:59:01.012: D/AbsListView(4199): unregisterIRListener() is called
10-30 00:59:02.162: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:59:02.162: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:59:05.132: E/problem(4199): Poblem is not in fetching data from editText
10-30 00:59:05.152: E/problem(4199): onCreate method of SQLite is called
10-30 00:59:05.152: E/problem(4199): Query Executed successfully
10-30 00:59:05.162: E/problem(4199): Poblem is not in method open
10-30 00:59:05.172: E/problem(4199): Poblem is not in method update
10-30 00:59:05.172: E/problem(4199): Poblem is not in if clause
10-30 00:59:05.242: D/TextLayoutCache(4199): Enable myanmar Zawgyi converter
10-30 00:59:08.312: W/InputEventReceiver(4199): Attempted to finish an input event but the input event receiver has already been disposed.
10-30 00:59:08.312: W/InputEventReceiver(4199): Attempted to finish an input event but the input event receiver has already been disposed.
10-30 00:59:08.312: W/ViewRootImpl(4199): Dropping event due to root view being removed: MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=392.0, y[0]=685.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=8998225, downTime=8998211, deviceId=9, source=0x1002 }
10-30 00:59:08.352: E/ViewRootImpl(4199): sendUserActionEvent() mView == null
10-30 00:59:11.282: W/ApplicationPackageManager(4199): getCSCPackageItemText()
10-30 00:59:11.302: E/MoreInfoHPW_ViewGroup(4199): Parent view is not a TextView
10-30 00:59:11.332: E/SQLiteLog(4199): (1) no such column: KEY_ROWID
10-30 00:59:11.332: D/AndroidRuntime(4199): Shutting down VM
10-30 00:59:11.332: W/dalvikvm(4199): threadid=1: thread exiting with uncaught exception (group=0x4174cda0)
10-30 00:59:11.342: E/AndroidRuntime(4199): FATAL EXCEPTION: main
10-30 00:59:11.342: E/AndroidRuntime(4199): Process: com.example.first, PID: 4199
10-30 00:59:11.342: E/AndroidRuntime(4199): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first/com.example.first.SqlView}: android.database.sqlite.SQLiteException: no such column: KEY_ROWID (code 1): , while compiling: SELECT KEY_ROWID, KEY_NAME, KEY_INTELLIGENCE FROM peopleTable
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.app.ActivityThread.access$800(ActivityThread.java:163)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.os.Handler.dispatchMessage(Handler.java:102)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.os.Looper.loop(Looper.java:157)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.app.ActivityThread.main(ActivityThread.java:5335)
10-30 00:59:11.342: E/AndroidRuntime(4199): at java.lang.reflect.Method.invokeNative(Native Method)
10-30 00:59:11.342: E/AndroidRuntime(4199): at java.lang.reflect.Method.invoke(Method.java:515)
10-30 00:59:11.342: E/AndroidRuntime(4199): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
10-30 00:59:11.342: E/AndroidRuntime(4199): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
10-30 00:59:11.342: E/AndroidRuntime(4199): at dalvik.system.NativeStart.main(Native Method)
10-30 00:59:11.342: E/AndroidRuntime(4199): Caused by: android.database.sqlite.SQLiteException: no such column: KEY_ROWID (code 1): , while compiling: SELECT KEY_ROWID, KEY_NAME, KEY_INTELLIGENCE FROM peopleTable
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:690)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1430)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1277)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1148)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1316)
10-30 00:59:11.342: E/AndroidRuntime(4199): at com.example.first.IntelligentOtNot.getData(IntelligentOtNot.java:89)
10-30 00:59:11.342: E/AndroidRuntime(4199): at com.example.first.SqlView.onCreate(SqlView.java:24)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.app.Activity.performCreate(Activity.java:5389)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
10-30 00:59:11.342: E/AndroidRuntime(4199): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256)
10-30 00:59:11.342: E/AndroidRuntime(4199): ... 11 more
10-30 01:04:11.372: I/Process(4199): Sending signal. PID: 4199 SIG: 9
10-30 01:04:11.722: W/ApplicationPackageManager(6061): getCSCPackageItemText()
10-30 01:04:11.722: I/PersonaManager(6061): getPersonaService() name persona_policy
10-30 01:04:11.772: E/MoreInfoHPW_ViewGroup(6061): Parent view is not a TextView
10-30 01:04:11.802: D/AbsListView(6061): Get MotionRecognitionManager
10-30 01:04:11.822: D/AbsListView(6061): onVisibilityChanged() is called, visibility : 4
10-30 01:04:11.822: D/AbsListView(6061): unregisterIRListener() is called
10-30 01:04:11.832: D/AbsListView(6061): onVisibilityChanged() is called, visibility : 0
10-30 01:04:11.832: D/AbsListView(6061): unregisterIRListener() is called
10-30 01:04:11.842: D/AbsListView(6061): unregisterIRListener() is called
10-30 01:04:11.852: D/TextLayoutCache(6061): Enable myanmar Zawgyi converter
10-30 01:04:11.872: I/Adreno-EGL(6061): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
10-30 01:04:11.872: I/Adreno-EGL(6061): OpenGL ES Shader Compiler Version: E031.24.00.08+13
10-30 01:04:11.872: I/Adreno-EGL(6061): Build Date: 03/28/14 Fri
10-30 01:04:11.872: I/Adreno-EGL(6061): Local Branch: 0328_AU200_patches
10-30 01:04:11.872: I/Adreno-EGL(6061): Remote Branch:
10-30 01:04:11.872: I/Adreno-EGL(6061): Local Patches:
10-30 01:04:11.872: I/Adreno-EGL(6061): Reconstruct Branch:
10-30 01:04:11.932: D/OpenGLRenderer(6061): Enabling debug mode 0
10-30 01:04:11.962: D/AbsListView(6061): unregisterIRListener() is called
Aucun commentaire:
Enregistrer un commentaire