<android>无法启动活动ComponentInfo </android>

时间:2014-01-20 18:40:57

标签: java android xml android-layout

我的申请表有问题。如果你能帮助我做一些事情,我将不胜感激,因为我是Android编程的初学者,我不知道这有什么问题。 这是我的日志:

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

这是来自活动文件错误的函数:

    @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);
}

我的布局:
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>

3 个答案:

答案 0 :(得分:2)

下次读取整个堆栈跟踪,而不是第一行。你到了那里:

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)

请查看SavedActvity.java,第34行并修复未初始化变量的使用。

答案 1 :(得分:1)

locationlist未初始化

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

确保您的activity_saved.xml包含ID为locationlist的列表视图。

答案 2 :(得分:0)

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