0

データをフェッチした後、アプリはカスタム アダプターを呼び出して ListView のデータを拡張しようとします。膨らませている間、次のエラーが表示されます。

02-21 11:14:39.156: E/AndroidRuntime(499): java.lang.NoClassDefFoundError: com.daedalus.sarkarinaukriblog.CustomAdapter$1
02-21 11:14:39.156: E/AndroidRuntime(499):  at com.daedalus.sarkarinaukriblog.CustomAdapter.<init>(CustomAdapter.java:42)
02-21 11:14:39.156: E/AndroidRuntime(499):  at com.daedalus.sarkarinaukriblog.ListActivity$DownloadFeeds.onPostExecute(ListActivity.java:176)
02-21 11:14:39.156: E/AndroidRuntime(499):  at com.daedalus.sarkarinaukriblog.ListActivity$DownloadFeeds.onPostExecute(ListActivity.java:1)
02-21 11:14:39.156: E/AndroidRuntime(499):  at android.os.AsyncTask.finish(AsyncTask.java:417)
02-21 11:14:39.156: E/AndroidRuntime(499):  at android.os.AsyncTask.access$300(AsyncTask.java:127)
02-21 11:14:39.156: E/AndroidRuntime(499):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
02-21 11:14:39.156: E/AndroidRuntime(499):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-21 11:14:39.156: E/AndroidRuntime(499):  at android.os.Looper.loop(Looper.java:123)
02-21 11:14:39.156: E/AndroidRuntime(499):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-21 11:14:39.156: E/AndroidRuntime(499):  at java.lang.reflect.Method.invokeNative(Native Method)
02-21 11:14:39.156: E/AndroidRuntime(499):  at java.lang.reflect.Method.invoke(Method.java:507)
02-21 11:14:39.156: E/AndroidRuntime(499):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-21 11:14:39.156: E/AndroidRuntime(499):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-21 11:14:39.156: E/AndroidRuntime(499):  at dalvik.system.NativeStart.main(Native Method)

私のオンポスト実行コード:

protected void onPostExecute(Boolean result) {
            // TODO Auto-generated method stub
            //super.onPostExecute(result);  
            try {
                if(result) {
                    adapterCust = new CustomAdapter(ListActivity.this, values);
                    listView1.setAdapter(adapterCust); 
                    progress.dismiss();                  
                } else {
                    progress.dismiss();
                    Toast.makeText(ListActivity.this, "Error in fetching data", Toast.LENGTH_SHORT).show();
                }               
            } catch(Exception e) {
                Toast.makeText(ListActivity.this, "Error in fetching data", Toast.LENGTH_SHORT).show();
            }
        }

私のジョブアダプター:

public class CustomAdapter extends BaseAdapter{
    Context context; 
    int layoutResourceId;    
    List<Map<String, String>> data = null;
    WeatherHolder holder = null;
    LruCache<String, Bitmap> mMemoryCache;


public CustomAdapter(Context context, List<Map<String, String>> data) {
    this.data = data;
    this.context = context;
    int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    // Use 1/8th of the available memory for this memory cache.
    int cacheSize = maxMemory / 8;

    mMemoryCache = new LruCache<String, Bitmap>(cacheSize){

    };
}

public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
    if (getBitmapFromMemCache(key) == null) {
        mMemoryCache.put(key, bitmap);
    }
}

public Bitmap getBitmapFromMemCache(String key) {
    return mMemoryCache.get(key);
}



@Override
public View getView(int position, View convertView, ViewGroup parent){
    View row = convertView;
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    row = inflater.inflate(R.layout.listview_row, null);
    holder = new WeatherHolder();
    holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
    holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
    holder.txtPubDate = (TextView)row.findViewById(R.id.txtPubDate);   
    holder.imgNext = (ImageView)row.findViewById(R.id.nextImg);
    row.setTag(holder);     
    holder.txtTitle.setText(getTitle(position));
    holder.txtPubDate.setText("Published Date : " + getPubDate(position));
    holder.imgNext.setColorFilter(Color.BLACK);
    Bitmap bm = getBitmapFromMemCache(String.valueOf(position));
    if( bm != null){
        holder.imgIcon.setImageBitmap(bm);
    }else {
          BitmapWorkerTask task = new BitmapWorkerTask(holder.imgIcon, position);
          task.execute(getUrl(position)); 
    }
    return row;
}

static class WeatherHolder
{
    ImageView imgIcon;
    TextView txtTitle;
    TextView txtPubDate;
    ImageView imgNext;
}

@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;
}

public String getTitle(int position) {
    Map<String, String> record = data.get(position);
    String title = record.get("title");
    return title;
}

public String getPubDate(int position) {
    Map<String, String> record = data.get(position);
    String pubdate = record.get("pubdate");
    return pubdate;
}

public String getDescription(int position) {
    Map<String, String> record = data.get(position);
    String description = record.get("description");
    return description;
}

public String getUrl(int position) {
    Map<String, String> record = data.get(position);
    String url = record.get("url");
    return url;
}

public String getactualUrl(int position) {
    Map<String, String> record = data.get(position);
    String acturl = record.get("actualURL");
    return acturl;
}



private class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
    private final WeakReference<ImageView> imageViewReference;
    private String url = null;
    private String key;
    public BitmapWorkerTask(ImageView imageView, int position) {
        // Use a WeakReference to ensure the ImageView can be garbage collected
        imageViewReference = new WeakReference<ImageView>(imageView);   
        this.key = String.valueOf(position); 
    }

    // Decode image in background.
    @Override
    protected Bitmap doInBackground(String... params) {
        url = params[0];
        return loadBitmap(url);
    }

    // Once complete, see if ImageView is still around and set bitmap.
    @Override
    protected void onPostExecute(Bitmap bitmap) {
        if (imageViewReference != null && bitmap != null) {
            final ImageView imageView = imageViewReference.get();
            if (imageView != null && imageView.isShown()) {
                Animation anim = AnimationUtils.loadAnimation(context, android.R.anim.fade_in);
                imageView.setAnimation(anim);
                imageView.setImageBitmap(bitmap); 
                anim.setDuration(5000);
                anim.start();
                addBitmapToMemoryCache(key, bitmap);
            }
        }
    }

    public Bitmap loadBitmap(String url) {
        Bitmap bm = null;
        try {
            URL aURL = new URL(url);
            URLConnection conn = aURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            bm = BitmapFactory.decodeStream(bis);
            bis.close();
            is.close();
       } catch (Exception e) {
          // Log.e(TAG, "Error getting bitmap", e);
       }


            return bm;
        }
    }   
}
4

2 に答える 2

1

プロジェクトをクリーンアップすると、問題が解決する場合があります

于 2013-02-21T05:48:49.097 に答える