简体   繁体   English

<Android>无法启动活动ComponentInfo

[英]<Android>Unable to start activity ComponentInfo

I have a problem in my Application. 我的申请表有问题。 I'll be grateful if You can help me to do something with it because I'm a beginer in Android programming and I have no idea what's wrong with this. 如果你能帮助我做一些事情,我将不胜感激,因为我是Android编程的初学者,我不知道这有什么问题。 This is my log: 这是我的日志:

01-20 19:02:42.452: E/AndroidRuntime(8834): FATAL EXCEPTION: main
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.app.ActivityThread.access$600(ActivityThread.java:135)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.os.Looper.loop(Looper.java:137)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.app.ActivityThread.main(ActivityThread.java:4849)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at java.lang.reflect.Method.invokeNative(Native Method)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at java.lang.reflect.Method.invoke(Method.java:511)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at dalvik.system.NativeStart.main(Native Method)
01-20 19:02:42.452: E/AndroidRuntime(8834): Caused by: java.lang.NullPointerException
01-20 19:02:42.452: E/AndroidRuntime(8834):     at com.example.locateme.SavedActivity.fillListViewData(SavedActivity.java:34)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at com.example.locateme.SavedActivity.initListView(SavedActivity.java:26)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at com.example.locateme.SavedActivity.onCreate(SavedActivity.java:22)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.app.Activity.performCreate(Activity.java:5244)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
01-20 19:02:42.452: E/AndroidRuntime(8834):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
01-20 19:02:42.452: E/AndroidRuntime(8834):     ... 11 more

And this is my functions from errors from activity file: 这是来自活动文件错误的函数:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_saved);
    initListView();
}

private void initListView() {
    fillListViewData();
}

private void fillListViewData() {
    locationDbAdapter = new LocationDbAdapter(getApplicationContext());
    locationDbAdapter.open();
    getAllLocations();
    listAdapter = new LocationList(this, locs);
    locationlist.setAdapter(listAdapter);
}

And my layout: 我的布局:
saved_activity.xml saved_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SavedActivity" >

<ListView
    android:id="@+id/locationlist"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
</ListView>

Read WHOLE stack trace next time, not the first line. 阅读整个堆栈跟踪下一次,不是第一线。 And you got there: 你到了那里:

01-20 19:02:42.452: E/AndroidRuntime(8834): Caused by: java.lang.NullPointerException
01-20 19:02:42.452: E/AndroidRuntime(8834):     at com.example.locateme.SavedActivity.fillListViewData(SavedActivity.java:34)

So look at your SavedActvity.java, line 34 and fix use of uninitialized variable. 请查看SavedActvity.java,第34行并修复未初始化变量的使用。

locationlist is not initialized locationlist未初始化

locationlist= (ListView)findViewById(R.id.locationlist);

Make sure your activity_saved.xml has a listview with id locationlist . 确保您的activity_saved.xml具有带有id locationlist的列表视图。

不应该是setContentView(R.layout.saved_activity);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM