2011-11-08 122 views
1

當我嘗試顯示數據列表時,我收到了服務器使用json與wcf webservices進行通信的錯誤信息。從webservice填充列表視圖

我收到來自Web服務響應和數據添加到還列出了,但我沒有得到爲什麼我收到這個error.Please指導我解決錯誤

這裏是logcat的輸出:

11-08 13:57:29.668: ERROR/AndroidRuntime(1386): Uncaught handler: thread main exiting due to uncaught exception 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.AdapterView.addView(AdapterView.java:461) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at com.ecommerce.balajeebazaar.CategoryListAdapter.getView(CategoryListAdapter.java:64) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.AbsListView.obtainView(AbsListView.java:1273) 
11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  
          at android.widget.ListView.measureHeightOfChildren(ListView.java:1147) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.ListView.onMeasure(ListView.java:1060) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.View.measure(View.java:7703) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:350) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:278) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.View.measure(View.java:7703) 
11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.View.measure(View.java:7703) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:464) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:278) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.View.measure(View.java:7703) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at android.view.View.measure(View.java:7703) 
11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  
          at android.view.ViewRoot.performTraversals(ViewRoot.java:747) 
11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  
          at android.view.ViewRoot.handleMessage(ViewRoot.java:1613) 
11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  
                       at android.os.Handler.dispatchMessage(Handler.java:99) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386): at android.os.Looper.loop(Looper.java:123) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386): at android.app.ActivityThread.main(ActivityThread.java:4203) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386): at java.lang.reflect.Method.invokeNative(Native Method) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386): at java.lang.reflect.Method.invoke(Method.java:521) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 

11-08 13:57:29.678: ERROR/AndroidRuntime(1386):  at dalvik.system.NativeStart.main(Native Method) 

而我的java文件的代碼是:

CategoryArray = CW.CategoryWebservice("http://www.balajeebazaar.com/RestServiceImpl.svc/categorydetails"); 

for(int i = 0;i<=CategoryArray.length()-1;i++){ 
      try { 
       Log.v("Categories :- ", CategoryArray.getString(i)+""); 
       String[] val = new String[3]; 
       val = CategoryArray.getString(i).split(","); 
       Log.v("val[0] : ", val[0]); 
       Log.v("val[1] :", val[1]); 
       CategoryList.add(i, val[0]+" "+val[1]); 
       val = null; 
       Log.v("CATEGORY LIST", CategoryList.get(i).toString()); 
      } catch (JSONException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
     //CategoryList.size(); 
     adapter = new CategoryListAdapter(CategoryActivity.this, CategoryList); 

我CategoryListAdapter類的代碼是:

public class CategoryListAdapter extends BaseAdapter { 
    private Activity activity; 
    // private String[] data; 
    private ArrayList<String> CategoryList = new ArrayList<String>(); 
    private static LayoutInflater inflater = null; 

    // public ImageLoader imageLoader; 

    public CategoryListAdapter(Activity a, ArrayList<String> categorylist) { 
     activity = a; 
     // data = d; 
     inflater = (LayoutInflater) activity 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     CategoryList = categorylist; 
     // imageLoader=new ImageLoader(activity.getApplicationContext()); 
    } 

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

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

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

    public static class ViewHolder { 
     public TextView text; 
     public ImageView image; 
    } 

代碼編輯:

@Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     View vi; 
     ViewHolder holder; 
     if (convertView == null) { 
      vi = new View(activity); 
      LayoutInflater inflater = activity.getLayoutInflater(); 
      vi = inflater.inflate(R.layout.item, null, true); 
      holder = new ViewHolder(); 
      holder.text = (TextView) vi.findViewById(R.id.text); 
      holder.image = (ImageView) vi.findViewById(R.id.image); 
      vi.setTag(holder); 
     } else { 
      vi = convertView; 
      holder = (ViewHolder) vi.getTag(); 
      holder.text.setText(CategoryList.get(position).toString()); 
      holder.image.setTag(R.drawable.go_arrow); 
     } 
     holder.text.setText(CategoryList.get(position).toString()); 
     holder.image.setTag(R.drawable.go_arrow); 
     vi.setTag(holder); 
     return vi; 
    } 
} 

我編輯的getView功能ablove(見我的代碼編輯) 和它的工作感謝名單大家的回覆

+0

看看我編輯的答案,你的適配器類我編輯,並讓我知道了什麼發生。 – user370305

回答

0

試試這個CategoryListAdapter在你更換,並讓我知道發生什麼事,

編輯:

public class CategoryListAdapter extends BaseAdapter { 
    private Activity activity; 
    // private String[] data; 
    private ArrayList<String> CategoryList = new ArrayList<String>(); 

    public CategoryListAdapter(Activity a, ArrayList<String> categorylist) { 
     activity = a; 
     CategoryList = categorylist; 

    } 

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

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

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

    public static class ViewHolder { 
     public TextView text; 
     public ImageView image; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     View vi; 
     ViewHolder holder; 
     if (convertView == null) { 
      LayoutInflater inflater =getLayoutInflater(); 
      vi = inflater.inflate(R.layout.item, parent); 
      holder = new ViewHolder(); 
      holder.text = (TextView) vi.findViewById(R.id.text); 
      holder.image = (ImageView) vi.findViewById(R.id.image); 
      vi.setTag(holder); 
     } else{ 
        vi = convertView; 
        holder = (ViewHolder) vi.getTag(); 
        } 
     String texttoappend = CategoryList.get(position); 
     Log.v("texttoappend", texttoappend); 
     holder.text.setText(CategoryList.get(position).toString()); 
     holder.image.setTag(R.drawable.go_arrow); 
     // imageLoader.DisplayImage(data[position], activity, holder.image); 
     return vi; 
    } 
} 
+0

感謝您的答覆..但它也不起作用 – Shruti

+0

你的提示幫助我解決了錯誤。謝謝 – Shruti

+0

隨時歡迎。 – user370305

0

請嘗試以下代碼

runOnUiThread(new Runnable() 
{   
    @Override 
    public void run() 
    { 
     adapter = new CategoryListAdapter(CategoryActivity.this, CategoryList); 

    } 
}); 
+0

感謝您的回覆,但我沒有問題,這一行適配器=新的CategoryListAdapter(CategoryActivity.this,CategoryList);我在我的適配器類中的getview()函數有問題 – Shruti

+0

我知道,但你有沒有嘗試過我給出的代碼,並且getView僅在setAdapter時調用,因此問題的根源在那一行 – ingsaurabh

+0

是的,我試過了,但是這也沒有爲我工作 – Shruti