0

エラーログ:

06-28 12:07:38.227: E/AndroidRuntime(1199): FATAL EXCEPTION: main
06-28 12:07:38.227: E/AndroidRuntime(1199): java.lang.NullPointerException
06-28 12:07:38.227: E/AndroidRuntime(1199):     at com.innoventes.cpea.view.DashboardAdapter.getView(DashboardAdapter.java:55)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.AbsListView.obtainView(AbsListView.java:1409)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.ListView.makeAndAddView(ListView.java:1745)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.ListView.fillSpecific(ListView.java:1290)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.ListView.layoutChildren(ListView.java:1576)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.AbsListView.onLayout(AbsListView.java:1260)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.view.View.layout(View.java:7175)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.view.View.layout(View.java:7175)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.view.View.layout(View.java:7175)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.view.View.layout(View.java:7175)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.os.Looper.loop(Looper.java:130)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at java.lang.reflect.Method.invokeNative(Native Method)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at java.lang.reflect.Method.invoke(Method.java:507)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-28 12:07:38.227: E/AndroidRuntime(1199):     at dalvik.system.NativeStart.main(Native Method)

私のアダプター:

public class DashboardAdapter extends ArrayAdapter<ProductModel>{

Context context;
List<ProductModel> item;

public DashboardAdapter(Context context, int resourceId,List<ProductModel> items) 
{
    super(context, resourceId, items);
    this.context = context;
    this.item = items;
}
/*private view holder class*/
private class ViewHolder 
{
    ImageButton rightCaret;
    TextView txtTitle;   
} 
public View getView(int position, View convertView, ViewGroup parent) 
{
    ViewHolder holder = new ViewHolder();
    ProductModel rowItem = getItem(position); 
    LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null)
    {
        convertView = mInflater.inflate(R.layout.dashboard_item,parent,false);
        holder = new ViewHolder();
        holder.txtTitle = (TextView) convertView.findViewById(R.id.dashboardItem_description);   
        holder.rightCaret = (ImageButton) convertView.findViewById(R.id.rightCaretDash);            
        holder.rightCaret.setTag(position); 
        holder.txtTitle.setText(rowItem.getProductTitle()); 
        convertView.setTag(holder);
        holder.rightCaret.setClickable(true);
        holder.rightCaret.setId(position);
        DashboardAdapter.this.notifyDataSetChanged();            
    }
    holder.rightCaret.setOnClickListener(new View.OnClickListener() 
    {            
    public void onClick(final View view) 
       {                 
            Integer index = (Integer) view.getTag(); 
            String header = item.get(index).toString();
            Intent intent = new Intent(context,ListProduct.class);
            intent.putExtra("value",header);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            context.startActivity(intent);
            notifyDataSetChanged();                                      
       }

    });

    convertView.setClickable(true);
    return convertView;
}

}

私がデバッグしたとき、rightCaret imageButton は null でした。さらに先に進む方法がわからないので、助けてください。

4

1 に答える 1

0
 if (convertView == null)  {
   //your code..
   convertView.setTag(holder);
} else 
    holder = (ViewHolder) convertView.getTag();

ViewHolderあなたはいつでも新しいものを作成しますgetView()が、そのフィールドは初期化されていません。

于 2013-06-28T07:19:22.273 に答える