常规ListActivity中的奇怪异常

时间:2012-05-17 20:46:47

标签: android android-layout android-widget android-listview

我在尝试设置NullPointerException的项目视图时收到ListActivity。完整的堆栈跟踪位于本文的底部,但我不确定它有多大帮助。以下是导致问题的一行:

 convertView = mInflater.inflate(R.layout.more_group_list_item, null);

由于异常提供的信息很少,我不知道为什么这一行会产生NullPointerException我不知道在哪里寻找解决问题的方法。我唯一的猜测是无法找到布局项目。

以下是上下文:

class MoreJumpListAdapter extends ArrayAdapter<MoreItem> {

    public MoreJumpListAdapter(final Context context) {
        super(context, 0);
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        MoreJumpActivity.ViewHolder viewHolder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.more_group_list_item, null);
            viewHolder = new MoreJumpActivity.ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (MoreJumpActivity.ViewHolder) convertView.getTag();
        }

        viewHolder.populateViews(getItem(position));

        return convertView;
    }

}

这里是布局xml文件内容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingRight="?android:attr/scrollbarSize"
    android:background="@color/white">
    <ImageView
        android:id="@+id/imageview_displayimage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:padding="5dp" />
    <TextView
        android:id="@+id/tv_displayname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:layout_centerVertical="true"
        android:paddingLeft="15dp"
        android:layout_toRightOf="@+id/imageview_displayimage" />
</RelativeLayout>

如果有人在这个堆栈跟踪中看到任何有用的东西,我很想知道它是什么。

05-17 20:34:22.224: W/dalvikvm(997): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-17 20:34:22.264: E/AndroidRuntime(997): FATAL EXCEPTION: main
05-17 20:34:22.264: E/AndroidRuntime(997): java.lang.NullPointerException
05-17 20:34:22.264: E/AndroidRuntime(997):  at com.MyApp.MoreJumpActivity$MoreJumpListAdapter.getView(MoreJumpActivity.java:103)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.AbsListView.obtainView(AbsListView.java:1430)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.ListView.makeAndAddView(ListView.java:1745)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.ListView.fillDown(ListView.java:670)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.ListView.fillFromTop(ListView.java:727)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.ListView.layoutChildren(ListView.java:1598)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.AbsListView.onLayout(AbsListView.java:1260)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.View.layout(View.java:7175)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.os.Looper.loop(Looper.java:123)
05-17 20:34:22.264: E/AndroidRuntime(997):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-17 20:34:22.264: E/AndroidRuntime(997):  at java.lang.reflect.Method.invokeNative(Native Method)
05-17 20:34:22.264: E/AndroidRuntime(997):  at java.lang.reflect.Method.invoke(Method.java:507)
05-17 20:34:22.264: E/AndroidRuntime(997):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-17 20:34:22.264: E/AndroidRuntime(997):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-17 20:34:22.264: E/AndroidRuntime(997):  at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

如果流量没有进入inflate方法,则mInflater必须为null,因此抛出。