Android ListView中奇怪的致命异常

时间:2012-03-17 21:00:33

标签: android listview exception fatal-error

我在Android世界中很新,我得到了一个我无法处理的令人困惑的错误。

我有以下ListView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

    </ListView>

</LinearLayout>

此活动:

package com.study.semesterplaner.vorlesungszeit;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.study.constants.IntentConstants;
import com.study.droid.R;
import common.vorlesung.Vorlesung;
import common.vorlesung.VorlesungszeitHaeufigkeit;
import common.vorlesung.vorlesungszeit.Vorlesungszeit;

public class VorlesungszeitListActivity extends Activity{

    private ListView _listView;
    private ArrayList<Vorlesungszeit> _vorlesungszeiten;
    private VorlesungszeitListAdapter _listAdapter;

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

        Vorlesung selectedVorlesung = (Vorlesung) getIntent().getExtras().get(IntentConstants.INTENT_VORLESUNG_DETAILS);
        _vorlesungszeiten = selectedVorlesung.getVorlesungsZeiten();

        _listView = (ListView) findViewById(R.id.listView1);
        _listAdapter = new VorlesungszeitListAdapter();
        _listView.setAdapter(_listAdapter);
    }

    private class VorlesungszeitListAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return _vorlesungszeiten.size();
        }

        @Override
        public Object getItem(int position) {
            return _vorlesungszeiten.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = convertView;
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.row_three_textviews, null);
            TextView top = (TextView) view.findViewById(R.id.row_three_textview_ONE);
            TextView mid = (TextView) view.findViewById(R.id.row_three_textview_TWO);
            TextView bottom = (TextView) view.findViewById(R.id.row_three_textview_THREE);

            Vorlesungszeit vZeit = _vorlesungszeiten.get(position);

            top.setText(vZeit.getTag() + ", " + vZeit.getVorlesungsbeginn() + " - " + vZeit.getVorlesungsende() + " Uhr");
            mid.setText("Raum: " + vZeit.getRaum());
            bottom.setText(VorlesungszeitHaeufigkeit.getHauefigkeitText(vZeit.getHaeufigkeit()));

            return view;
        }

    }
}

如果我尝试启动此活动,我会得到这个奇怪的异常:

03-17 21:48:38.867: E/AndroidRuntime(8864): FATAL EXCEPTION: main
03-17 21:48:38.867: E/AndroidRuntime(8864): java.lang.NullPointerException
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.ListView.measureScrapChild(ListView.java:1136)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1267)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.ListView.onMeasure(ListView.java:1128)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3257)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3257)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3257)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3257)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3257)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3257)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3257)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3257)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3257)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.View.measure(View.java:8524)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewRoot.performTraversals(ViewRoot.java:915)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1991)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.os.Looper.loop(Looper.java:150)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at android.app.ActivityThread.main(ActivityThread.java:4293)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at java.lang.reflect.Method.invokeNative(Native Method)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at java.lang.reflect.Method.invoke(Method.java:507)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
03-17 21:48:38.867: E/AndroidRuntime(8864):     at dalvik.system.NativeStart.main(Native Method)

我不知道出了什么问题。我试图用调试器查找故障排除代码,但程序甚至不访问活动的onCreate Methode ......

1 个答案:

答案 0 :(得分:0)

导入com.study.droid.R似乎对我很怀疑