2 momo1199 Momo1199 于 2012.12.26 14:21 提问

ListView中的横向ListView

我在ListView中创建了一个横向的ListView,但是遇到点问题:

myAdapter adapter = new myAdapter(thisActivity, kategoriList,
                        R.layout.list_item,
                        new String[] { "nama","thumbnail"}, new int[] {
                                R.id.name, R.id.thumb_kategori});

                setListAdapter(adapter);

                HorizontalListView listview = (HorizontalListView) findViewById(R.id.listview2);
                listview.setAdapter(mAdapter);

布局文件如下,横向的ListView来自Dev-SmartLib:

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

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent" >

            <ImageView
                android:id="@+id/thumb_kategori"
                android:layout_width="40dp"
                android:layout_height="40dp" />

            <TextView
                android:id="@+id/name"
                android:layout_width="238dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:paddingBottom="2dip"
                android:paddingTop="6dip"
                android:textColor="#43bd00"
                android:textSize="16sp"
                android:textStyle="bold" />

        </LinearLayout>
    <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content" >

      <com.devsmart.android.ui.HorizontalListView
          android:id="@+id/listview2"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginBottom="40dp"
          android:layout_marginLeft="70dp"
          android:layout_marginRight="70dp"
          android:layout_marginTop="50dp"
          android:divider="#FFCC00"
          android:fillViewport="false" >

      </com.devsmart.android.ui.HorizontalListView>

  </RelativeLayout>

    </LinearLayout>

</LinearLayout>

但是在运行时出错了,日志如下:

12-26 11:09:16.350: E/AndroidRuntime(7102): FATAL EXCEPTION: main
12-26 11:09:16.350: E/AndroidRuntime(7102): java.lang.NullPointerException
12-26 11:09:16.350: E/AndroidRuntime(7102):     at com.lluvia.digilib.DashboardActivity$HeavyWorker.onPostExecute(DashboardActivity.java:468)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at com.lluvia.digilib.DashboardActivity$HeavyWorker.onPostExecute(DashboardActivity.java:1)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at android.os.AsyncTask.finish(AsyncTask.java:590)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at android.os.AsyncTask.access$600(AsyncTask.java:149)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:603)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at android.os.Looper.loop(Looper.java:132)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at android.app.ActivityThread.main(ActivityThread.java:4123)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at java.lang.reflect.Method.invokeNative(Native Method)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at java.lang.reflect.Method.invoke(Method.java:491)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
12-26 11:09:16.350: E/AndroidRuntime(7102):     at dalvik.system.NativeStart.main(Native Method)

1个回答

cytown
cytown   2012.12.26 15:52

AsyncTask的时候出的空指针,把那部分代码贴出来才能知道。

此外,最好标行号。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!