2014-12-04 46 views
0

我正在試圖開發一個購物車。我想從SQLite數據庫的自定義ListView中顯示產品詳細信息,按鈕單擊。但我的Adapter.My出現一些錯誤錯誤日誌Adapter.java給出。請幫助我。Android:ListView適配器中的空點異常

錯誤日誌

12-04 11:26:30.856: E/AndroidRuntime(24522): FATAL EXCEPTION: main 
12-04 11:26:30.856: E/AndroidRuntime(24522): java.lang.NullPointerException 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.AbsListView.obtainView(AbsListView.java:1317) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.ListView.measureHeightOfChildren(ListView.java:1198) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.ListView.onMeasure(ListView.java:1109) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.View.measure(View.java:8171) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.View.measure(View.java:8171) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.View.measure(View.java:8171) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.View.measure(View.java:8171) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.View.measure(View.java:8171) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.ViewRoot.performTraversals(ViewRoot.java:801) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.os.Handler.dispatchMessage(Handler.java:99) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.os.Looper.loop(Looper.java:123) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at android.app.ActivityThread.main(ActivityThread.java:4627) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at java.lang.reflect.Method.invokeNative(Native Method) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at java.lang.reflect.Method.invoke(Method.java:521) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
12-04 11:26:30.856: E/AndroidRuntime(24522): at dalvik.system.NativeStart.main(Native Method) 
12-04 11:26:33.519: I/Process(24522): Sending signal. PID: 24522 SIG: 9 

CartAdapter.java

public class CartAdapter extends BaseAdapter { 
private final String[] pname; 
private final String[] price; 
private Context cntxt; 

public CartAdapter(Context c,String [] pname,String [] price) { 
    cntxt=c; 
    this.pname=pname; 
    this.price=price; 
} 

@Override 
public int getCount() { 
    // TODO Auto-generated method stub 
    return pname.length; 
} 

@Override 
public Object getItem(int position) { 
    // TODO Auto-generated method stub 
    return null; 
} 

@Override 
public long getItemId(int position) { 
    // TODO Auto-generated method stub 
    return 0; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 
    View List; 
    LayoutInflater mLayoutInflater=(LayoutInflater)cntxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    if (convertView==null) { 
     List=new View(cntxt); 
     List=mLayoutInflater.inflate(R.layout.add2crt_sub,parent, false); 
    } else { 
     List=(View)convertView; 
    } 
    // ImageView imageview=(ImageView)List.findViewById(R.id.prdt_pic); 
    TextView nametxt=(TextView)List.findViewById(R.id.prdt_nme); 
    TextView pricetxt=(TextView)List.findViewById(R.id.prdt_rate); 
    nametxt.setText(pname[position].toString()); 
    pricetxt.setText("Rs "+price[position] +" /-"); 

    return null; 
} 

} 
+1

你return語句是空 換回清單; – Jaydeep 2014-12-04 07:39:22

回答

5

您正在返回null視圖。

替換getView()方法

return null; 

return List; 

,並刪除這條線也

List=new View(cntxt); 
+0

謝謝..我工作。 – droid 2014-12-04 07:50:18