遅延画像ローダー コードをダウンロードしました:リンク
コードに実装しましたが、NPE がスローされ、その理由がわかりません。これらのクラスを見下ろしましたが、役立つものは何も見つかりませんでした。
それが私のアダプターの外観です:
public class MobileArrayAdapter extends ArrayAdapter<List<item>> {
private final Context context;
private final List<item> markers;
public ImageLoader imageLoader;
ImageView image;
ProgressBar loader;
public MobileArrayAdapter(Context context, List<item> markers) {
super(context, R.layout.list_item);
this.context = context;
this.markers = markers;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewHolder holder;
View rowView = inflater.inflate(R.layout.list_item, parent, false);
TextView title = (TextView) rowView.findViewById(R.id.title);
loader = (ProgressBar) rowView.findViewById(R.id.loader);
image = (ImageView) rowView.findViewById(R.id.itemimgae);
TextView views = (TextView) rowView.findViewById(R.id.views);
TextView likes = (TextView) rowView.findViewById(R.id.likes);
TextView upvote = (TextView) rowView.findViewById(R.id.upvote);
TextView downvote = (TextView) rowView.findViewById(R.id.downvote);
TextView desc = (TextView) rowView.findViewById(R.id.desc);
TextView pub = (TextView) rowView.findViewById(R.id.pub);
TextView idnum = (TextView) rowView.findViewById(R.id.idnum);
title.setText(" " + markers.get(position).getTitle());
views.setText(markers.get(position).getView() + "");
likes.setText(markers.get(position).getLike() + "");
upvote.setText(markers.get(position).getUpvote() + "");
downvote.setText(markers.get(position).getDownvote() + "");
desc.setText(markers.get(position).getDesc());
pub.setText(markers.get(position).getPub() + "");
idnum.setText(markers.get(position).getId() + "");
imageLoader.DisplayImage("http://apple.sourcherry.tk/freeapp/resize.php?h=400&img=upload/id"
+ markers.get(position).getId() + ".jpg", image);
return rowView;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return (this.markers != null) ? this.markers.size() : 0;
}
public void deleteList() {
markers.clear();
}
}
残りのコードは、github へのリンクにあります。
使用するクラスは次のimageLoader
とおりです。
ImageLoader.java
、FileCache.java
、MemoryCache.java
およびUtils.java
。
ログキャット:
11-12 22:57:04.824: W/dalvikvm(12066): threadid=1: thread exiting with uncaught exception (group=0x41396930)
11-12 22:57:04.844: E/AndroidRuntime(12066): FATAL EXCEPTION: main
11-12 22:57:04.844: E/AndroidRuntime(12066): java.lang.NullPointerException
11-12 22:57:04.844: E/AndroidRuntime(12066): at com.example.free.MobileArrayAdapter.getView(MobileArrayAdapter.java:76)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.AbsListView.obtainView(AbsListView.java:2159)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.ListView.measureHeightOfChildren(ListView.java:1246)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.ListView.onMeasure(ListView.java:1158)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.View.measure(View.java:15525)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:666)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.View.measure(View.java:15525)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.View.measure(View.java:15525)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.View.measure(View.java:15525)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.View.measure(View.java:15525)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.View.measure(View.java:15525)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.View.measure(View.java:15525)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-12 22:57:04.844: E/AndroidRuntime(12066): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2438)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.View.measure(View.java:15525)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.Choreographer.doFrame(Choreographer.java:532)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.os.Handler.handleCallback(Handler.java:725)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.os.Handler.dispatchMessage(Handler.java:92)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.os.Looper.loop(Looper.java:137)
11-12 22:57:04.844: E/AndroidRuntime(12066): at android.app.ActivityThread.main(ActivityThread.java:5227)
11-12 22:57:04.844: E/AndroidRuntime(12066): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 22:57:04.844: E/AndroidRuntime(12066): at java.lang.reflect.Method.invoke(Method.java:511)
11-12 22:57:04.844: E/AndroidRuntime(12066): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
11-12 22:57:04.844: E/AndroidRuntime(12066): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
11-12 22:57:04.844: E/AndroidRuntime(12066): at dalvik.system.NativeStart.main(Native Method)
お手伝いいただきありがとうございます!
行 76:
imageLoader.DisplayImage("http://apple.sourcherry.tk/freeapp/resize.php?h=400&img=upload/id"
+ markers.get(position).getId() + ".jpg", image);