-1

我有從服務器加載圖像列表適配器作爲圖標列表。我想我沒有在我的適配器的關鍵問題,但我仍然有錯誤,即使我已經編輯我的代碼。我使用asynctask類從服務器加載數據。在這裏我的適配器代碼:加載圖像爲列表視圖時出現Android錯誤

public class ListAdapterImage extends BaseAdapter{ 

    private Activity activity; 
    private Runnable runnable; 
    private ArrayList<HashMap<String, String>> data; 
    private static LayoutInflater inflater=null; 
    public ImageLoader imageLoader; 

    public ListAdapterImage (Activity a, ArrayList<HashMap<String, String>> data) { 
     activity = a; 
     this.data=data; 
     inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     imageLoader=new ImageLoader(activity.getApplicationContext()); 
    } 

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

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

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

    @Override 
    public View getView(int position, View v, ViewGroup parent) { 

     View vi=v; 
      if(v==null) 
       vi = inflater.inflate(R.layout.list_row, null); 

      TextView Pk_Merchant_ID = (TextView) vi.findViewById(R.id.tv_id); 
      TextView Descriptions = (TextView) vi.findViewById(R.id.tv_groupname); 
      TextView Address = (TextView) vi.findViewById(R.id.tv_merchantname); 
      ImageView imgythumb = (ImageView) vi.findViewById(R.id.list_images); 

      HashMap<String, String> datas = new HashMap<String, String>(); 
       datas = data.get(position); 

      Pk_Merchant_ID.setText(datas.get("Pk_Merchant_ID")); 
      Descriptions.setText(datas.get("Descriptions")); 
      Address.setText(datas.get("Address")); 
      imageLoader.DisplayImage(datas.get("Path_PhotoProfile"), imgythumb); 
     return vi; 
    } 

} 

在我的logcat一些像這樣的錯誤:

11-10 22:52:02.732: E/AndroidRuntime(26274): FATAL EXCEPTION: main 
11-10 22:52:02.732: E/AndroidRuntime(26274): java.lang.NullPointerException 
11-10 22:52:02.732: E/AndroidRuntime(26274): at com.example.adapter.ListAdapterImage.<init>(ListAdapterImage.java:30) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at com.example.main.ResultRestoActivity$LoadData$1.run(ResultRestoActivity.java:271) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at android.app.Activity.runOnUiThread(Activity.java:3743) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at com.example.main.ResultRestoActivity$LoadData.onPostExecute(ResultRestoActivity.java:258) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at com.example.main.ResultRestoActivity$LoadData.onPostExecute(ResultRestoActivity.java:1) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at android.os.AsyncTask.finish(AsyncTask.java:417) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at android.os.AsyncTask.access$300(AsyncTask.java:127) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at android.os.Handler.dispatchMessage(Handler.java:99) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at android.os.Looper.loop(Looper.java:130) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at android.app.ActivityThread.main(ActivityThread.java:3691) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at java.lang.reflect.Method.invokeNative(Native Method) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at java.lang.reflect.Method.invoke(Method.java:507) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 
11-10 22:52:02.732: E/AndroidRuntime(26274): at dalvik.system.NativeStart.main(Native Method) 
在我的活動

,我把我的適配器onPostExecute

@Override 
    protected void onPostExecute(String s) { 
     pDialog.dismiss(); 
     runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       adapter = new ListAdapterImage(null, listData); 
       lv.setAdapter(adapter); 
      } 
     }); 
    } 

需要您的所有幫助並立即發表評論。感謝提前。

回答

0

你逝去空在這裏..

adapter = new ListAdapterImage(null, listData); 

,然後在這段代碼

public ListAdapterImage (Activity a, ArrayList<HashMap<String, String>> data) { 
    activity = a; 
    this.data=data; 
    //Problem 
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    imageLoader=new ImageLoader(activity.getApplicationContext()); 
} 

adapter = new ListAdapterImage(yourActivityName.this, listData);

+0

@M穆赫辛納伊姆感謝先生,它的工作:-) –

相關問題