java - Android SQlite application crashes when I try to run it -
i have attempted create viewable sqlite database view keeps crashing when try open it.
have tried opening multiple times , changed few things try , fix it, seeing have not fixed made worse.
can't anywhere when open , crashes straight away. sorry wall of code thought may aswell give info rather little.
input appreciated.
dbhelper.java
package com.example.listviewfromsqlitedb; import android.content.context; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteexception; import android.database.sqlite.sqliteopenhelper; public class dbhelper extends sqliteopenhelper{ public sqlitedatabase db; public string dbpath; public static string dbname = "sample"; public static final int version = '1'; public static context currentcontext; public static string tablename = "resource"; public dbhelper(context context) { super(context, dbname, null, version); currentcontext = context; dbpath = "/data/data/" + context.getpackagename() + "/databases"; createdatabase(); } @override public void oncreate(sqlitedatabase db) { // todo auto-generated method stub } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { // todo auto-generated method stub } private void createdatabase() { boolean dbexists = checkdbexists(); if (dbexists) { // nothing } else { db = currentcontext.openorcreatedatabase(dbname, 0, null); db.execsql("create table if not exists " + tablename + " (lastname varchar, firstname varchar," + " country varchar, age int(3));"); db.execsql("insert " + tablename + " values ('m','shumi','india',25);"); db.execsql("insert " + tablename + " values ('c','sarah','india',25);"); db.execsql("insert " + tablename + " values ('d','lavya','usa',20);"); db.execsql("insert " + tablename + " values ('v','avi','eu',25);"); db.execsql("insert " + tablename + " values ('t','shenoi','bangla',25);"); db.execsql("insert " + tablename + " values ('l','lamha','australia',20);"); } } private boolean checkdbexists() { sqlitedatabase checkdb = null; try { string mypath = dbpath + dbname; checkdb = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readonly); } catch (sqliteexception e) { // database does't exist yet. } if (checkdb != null) { checkdb.close(); } return checkdb != null ? true : false; } }
listviewfromsqlitedb.java
package com.example.listviewfromsqlitedb; import android.support.v7.app.actionbaractivity; import android.support.v7.app.actionbar; import android.support.v4.app.fragment; import android.os.bundle; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.os.build; public class listviewfromsqlitedb extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); if (savedinstancestate == null) { getsupportfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()).commit(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } /** * placeholder fragment containing simple view. */ public static class placeholderfragment extends fragment { public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); return rootview; } } }
androidmanifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.listviewfromsqlitedb" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="19" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <activity android:name="com.example.listviewfromsqlitedb.datalistview" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello_world" /> </linearlayout>
logcat:
05-16 23:31:02.535: d/androidruntime(31302): shutting down vm 05-16 23:31:02.555: w/dalvikvm(31302): threadid=1: thread exiting uncaught exception (group=0x4143f2a0) 05-16 23:31:02.585: e/androidruntime(31302): fatal exception: main 05-16 23:31:02.585: e/androidruntime(31302): java.lang.runtimeexception: unable start activity componentinfo{com.example.listviewfromsqlitedb/com.example.listviewfromsqlitedb.listviewfromsqlitedb}: java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity. 05-16 23:31:02.585: e/androidruntime(31302): @ android.app.activitythread.performlaunchactivity(activitythread.java:2100) 05-16 23:31:02.585: e/androidruntime(31302): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2125) 05-16 23:31:02.585: e/androidruntime(31302): @ android.app.activitythread.access$600(activitythread.java:140) 05-16 23:31:02.585: e/androidruntime(31302): @ android.app.activitythread$h.handlemessage(activitythread.java:1227) 05-16 23:31:02.585: e/androidruntime(31302): @ android.os.handler.dispatchmessage(handler.java:99) 05-16 23:31:02.585: e/androidruntime(31302): @ android.os.looper.loop(looper.java:137) 05-16 23:31:02.585: e/androidruntime(31302): @ android.app.activitythread.main(activitythread.java:4898) 05-16 23:31:02.585: e/androidruntime(31302): @ java.lang.reflect.method.invokenative(native method) 05-16 23:31:02.585: e/androidruntime(31302): @ java.lang.reflect.method.invoke(method.java:511) 05-16 23:31:02.585: e/androidruntime(31302): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1006) 05-16 23:31:02.585: e/androidruntime(31302): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:773) 05-16 23:31:02.585: e/androidruntime(31302): @ dalvik.system.nativestart.main(native method) 05-16 23:31:02.585: e/androidruntime(31302): caused by: java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity. 05-16 23:31:02.585: e/androidruntime(31302): @ android.support.v7.app.actionbaractivitydelegate.oncreate(actionbaractivitydelegate.java:108) 05-16 23:31:02.585: e/androidruntime(31302): @ android.support.v7.app.actionbaractivitydelegateics.oncreate(actionbaractivitydelegateics.java:57) 05-16 23:31:02.585: e/androidruntime(31302): @ android.support.v7.app.actionbaractivity.oncreate(actionbaractivity.java:98) 05-16 23:31:02.585: e/androidruntime(31302): @ com.example.listviewfromsqlitedb.listviewfromsqlitedb.oncreate(listviewfromsqlitedb.java:18) 05-16 23:31:02.585: e/androidruntime(31302): @ android.app.activity.performcreate(activity.java:5206) 05-16 23:31:02.585: e/androidruntime(31302): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1083) 05-16 23:31:02.585: e/androidruntime(31302): @ android.app.activitythread.performlaunchactivity(activitythread.java:2064) 05-16 23:31:02.585: e/androidruntime(31302): ... 11 more 05-16 23:31:42.800: d/androidruntime(32421): shutting down vm 05-16 23:31:42.800: w/dalvikvm(32421): threadid=1: thread exiting uncaught exception (group=0x4143f2a0) 05-16 23:31:42.810: e/androidruntime(32421): fatal exception: main 05-16 23:31:42.810: e/androidruntime(32421): java.lang.runtimeexception: unable start activity componentinfo{com.example.listviewfromsqlitedb/com.example.listviewfromsqlitedb.listviewfromsqlitedb}: java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity. 05-16 23:31:42.810: e/androidruntime(32421): @ android.app.activitythread.performlaunchactivity(activitythread.java:2100) 05-16 23:31:42.810: e/androidruntime(32421): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2125) 05-16 23:31:42.810: e/androidruntime(32421): @ android.app.activitythread.access$600(activitythread.java:140) 05-16 23:31:42.810: e/androidruntime(32421): @ android.app.activitythread$h.handlemessage(activitythread.java:1227) 05-16 23:31:42.810: e/androidruntime(32421): @ android.os.handler.dispatchmessage(handler.java:99) 05-16 23:31:42.810: e/androidruntime(32421): @ android.os.looper.loop(looper.java:137) 05-16 23:31:42.810: e/androidruntime(32421): @ android.app.activitythread.main(activitythread.java:4898) 05-16 23:31:42.810: e/androidruntime(32421): @ java.lang.reflect.method.invokenative(native method) 05-16 23:31:42.810: e/androidruntime(32421): @ java.lang.reflect.method.invoke(method.java:511) 05-16 23:31:42.810: e/androidruntime(32421): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1006) 05-16 23:31:42.810: e/androidruntime(32421): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:773) 05-16 23:31:42.810: e/androidruntime(32421): @ dalvik.system.nativestart.main(native method) 05-16 23:31:42.810: e/androidruntime(32421): caused by: java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity. 05-16 23:31:42.810: e/androidruntime(32421): @ android.support.v7.app.actionbaractivitydelegate.oncreate(actionbaractivitydelegate.java:108) 05-16 23:31:42.810: e/androidruntime(32421): @ android.support.v7.app.actionbaractivitydelegateics.oncreate(actionbaractivitydelegateics.java:57) 05-16 23:31:42.810: e/androidruntime(32421): @ android.support.v7.app.actionbaractivity.oncreate(actionbaractivity.java:98) 05-16 23:31:42.810: e/androidruntime(32421): @ com.example.listviewfromsqlitedb.listviewfromsqlitedb.oncreate(listviewfromsqlitedb.java:18) 05-16 23:31:42.810: e/androidruntime(32421): @ android.app.activity.performcreate(activity.java:5206) 05-16 23:31:42.810: e/androidruntime(32421): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1083) 05-16 23:31:42.810: e/androidruntime(32421): @ android.app.activitythread.performlaunchactivity(activitythread.java:2064) 05-16 23:31:42.810: e/androidruntime(32421): ... 11 more
java.lang.classnotfoundexception: com.example.listviewfromsqlitedb.datalistview
you declared class in androidmanifest.xml
not seem exist. maybe mean was:
<activity android:name="com.example.listviewfromsqlitedb.listviewfromsqlitedb" android:label="@string/app_name">
also note each activity intend launch have declared in androidmanifest.xml
. if full xml have declare mainactivity
.
Comments
Post a Comment