0

遅延画像ローダー コードをダウンロードしました:リンク

コードに実装しましたが、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.javaFileCache.javaMemoryCache.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);
4

2 に答える 2

2

アダプターimageLoaderで初期化していないため、null です。コンストラクターに初期化を追加します。

public MobileArrayAdapter(Context context, List<item> markers) {
    super(context, R.layout.list_item);
    this.context = context;
    this.markers = markers;
    this.imageLoader = new ImageLoader(context.getApplicationContext());
}

そしてそれはうまくいくはずです。

編集:そして第二に、ViewHolderビューを初期化するために使用することを検討する必要がありますgetView()

于 2013-11-12T21:21:25.127 に答える
0

初期化していないようですimageLoader。あなたはそれを宣言します

ublic class MobileArrayAdapter extends ArrayAdapter<List<item>> {

private final Context context;
private final List<item> markers;
public ImageLoader imageLoader;   // here

しかし、あなたはそれを初期化することはありません。コンストラクターで初期化する必要があります。

リンク先のコードで彼らがどのようにそれを行うかを確認してください

 public LazyAdapter(Activity a, String[] d) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());   //Here
于 2013-11-12T21:21:40.273 に答える