“无法开始活动”错误
我的代码:
private void filldata(){
Cursor datacursor = sqlite.fetchalldata("Program");
startManagingCursor(datacursor);
String[] from = new String[]{DatabaseHelper.KEY_PROGRAM_DATE, DatabaseHelper.KEY_PROGRAM_TIME, DatabaseHelper.KEY_PROGRAM_CHANNEL};
String[] from1 = new String[]{DatabaseHelper.KEY_PROGRAM_TITLE};
int[] to = new int[]{R.id.programdate, R.id.programtime, R.id.programchannel};
int[] to1 = new int[]{R.id.programtitle};
SimpleExpandableListAdapter SEL = new SimpleExpandableListAdapter(this,
createGroupList(), R.layout.programgroup_row, from1, to1,
createChildList(), R.layout.programchild_row, from, to);
setListAdapter( SEL );
}
当我在 oncreate()
中调用 filldata()
时,Logcat
给了我这个错误:
04-27 03:43:10.066: WARN/dalvikvm(279): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): FATAL EXCEPTION: main
04-27 03:43:10.146: ERROR/AndroidRuntime(279): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.imammuda/com.android.imammuda.ImamMuda}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.imammuda/com.android.imammuda.Program}: java.lang.NullPointerException
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.os.Looper.loop(Looper.java:123)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at java.lang.reflect.Method.invoke(Method.java:521)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at dalvik.system.NativeStart.main(Native Method)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.imammuda/com.android.imammuda.Program}: java.lang.NullPointerException
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.widget.TabHost.addTab(TabHost.java:213)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.imammuda.ImamMuda.onCreate(ImamMuda.java:26)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): ... 11 more
04-27 03:43:10.146: ERROR/AndroidRuntime(279): Caused by: java.lang.NullPointerException
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.imammuda.Program.createGroupList(Program.java:91)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.imammuda.Program.filldata(Program.java:45)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.imammuda.Program.onCreate(Program.java:29)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): ... 20 more
*其他类
Databasehelper extends SqliteOpenHelper
sqlite 从/到 获取了
open
、close
、createdata
、fetchdata
databasehelper
我想知道为什么当我调用该函数时会出现此错误,而当我不调用它时却没有问题。
My code:
private void filldata(){
Cursor datacursor = sqlite.fetchalldata("Program");
startManagingCursor(datacursor);
String[] from = new String[]{DatabaseHelper.KEY_PROGRAM_DATE, DatabaseHelper.KEY_PROGRAM_TIME, DatabaseHelper.KEY_PROGRAM_CHANNEL};
String[] from1 = new String[]{DatabaseHelper.KEY_PROGRAM_TITLE};
int[] to = new int[]{R.id.programdate, R.id.programtime, R.id.programchannel};
int[] to1 = new int[]{R.id.programtitle};
SimpleExpandableListAdapter SEL = new SimpleExpandableListAdapter(this,
createGroupList(), R.layout.programgroup_row, from1, to1,
createChildList(), R.layout.programchild_row, from, to);
setListAdapter( SEL );
}
when I call filldata()
in oncreate()
, the Logcat
gave me this error:
04-27 03:43:10.066: WARN/dalvikvm(279): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): FATAL EXCEPTION: main
04-27 03:43:10.146: ERROR/AndroidRuntime(279): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.imammuda/com.android.imammuda.ImamMuda}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.imammuda/com.android.imammuda.Program}: java.lang.NullPointerException
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.os.Looper.loop(Looper.java:123)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at java.lang.reflect.Method.invoke(Method.java:521)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at dalvik.system.NativeStart.main(Native Method)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.imammuda/com.android.imammuda.Program}: java.lang.NullPointerException
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.widget.TabHost.addTab(TabHost.java:213)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.imammuda.ImamMuda.onCreate(ImamMuda.java:26)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): ... 11 more
04-27 03:43:10.146: ERROR/AndroidRuntime(279): Caused by: java.lang.NullPointerException
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.imammuda.Program.createGroupList(Program.java:91)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.imammuda.Program.filldata(Program.java:45)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at com.android.imammuda.Program.onCreate(Program.java:29)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-27 03:43:10.146: ERROR/AndroidRuntime(279): ... 20 more
*Other classes
Databasehelper extends SqliteOpenHelper
sqlite which got open
, close
, createdata
, fetchdata
from/to the databasehelper
I want to know why I get this error when I the function and no issues when I do not call it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它在
Program
类第 91 行中遇到了NullPointer Exception
。检查该行并尝试解决此空指针异常Its hitting a
NullPointer Exception
in theProgram
class line number 91. Check that line and try to resolve this null pointer exception