0

ListView を LinkedList で埋めようとしています。実装に何か問題があると思います..しかし、何がわかりません。

これは、私がアダプタを設定している方法です:

public void refreshListView() {
    //pManager.simpleSort();
    // pManager.getProfiles()

    LinkedList<Profile> temp = new LinkedList<Profile>();
    temp.add(new Profile("hello", "link", true)); // im kind of testing here
    adapter = new CustomAdapter(getApplicationContext(), temp);
    list.setAdapter(adapter);
}

これは、いくつかのチュートリアルを使用して作成した CustomAdapter です。

public class CustomAdapter extends BaseAdapter {

    private LinkedList<Profile> profiles;
    private Context context;

    public CustomAdapter(Context context, LinkedList<Profile> input) {
        this.context = context;
        profiles = input;
    }

    @Override
    public int getCount() {
        if (profiles == null) {
            return 0;
        } else {
            return profiles.size();
        }
    }

    @Override
    public Profile getItem(int arg0) {
        return profiles.get(arg0);
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {
        View out = v;
        if (out == null){
            out = new ProfileItemView(context, getItem(position));
        }
        return out;
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }
}

これは、プロファイルを表示するために作成したカスタム ビューです。

public class ProfileItemView extends RelativeLayout {

    public ProfileItemView(Context context, Profile profile) {
        super(context, null);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.list_item, null, true);
        ImageView icon = (ImageView) findViewById(R.id.default_icon_view);
        if (profile.checkDefault()) {
            icon.setImageResource(R.drawable.ic_launcher);
        } else {
            icon.setImageResource(R.drawable.android_icon);
        }
        TextView name = (TextView) findViewById(R.id.name_view);
        name.setText(profile.getName());
    }
}

また、ここにlogcatがあります:

Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x419c52a0)
FATAL EXCEPTION: main
java.lang.NullPointerException
   at com.exp.test.ProfileItemView.<init>(ProfileItemView.java:18)
   at com.exp.test.CustomAdapter.getView(CustomAdapter.java:37)
   at android.widget.AbsListView.obtainView(AbsListView.java:2402)
   at android.widget.ListView.makeAndAddView(ListView.java:1769)
   at android.widget.ListView.fillDown(ListView.java:672)
   at android.widget.ListView.fillFromTop(ListView.java:733)
   at android.widget.ListView.layoutChildren(ListView.java:1622)
   at android.widget.AbsListView.onLayout(AbsListView.java:2237)
   at android.view.View.layout(View.java:13840)
   at android.view.ViewGroup.layout(ViewGroup.java:4372)
   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
   at android.view.View.layout(View.java:13840)
   at android.view.ViewGroup.layout(ViewGroup.java:4372)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
   at android.view.View.layout(View.java:13840)
   at android.view.ViewGroup.layout(ViewGroup.java:4372)
   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
   at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
   at android.view.View.layout(View.java:13840)
   at android.view.ViewGroup.layout(ViewGroup.java:4372)
   at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
   at android.view.View.layout(View.java:13840)
   at android.view.ViewGroup.layout(ViewGroup.java:4372)
   at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1948)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1758)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1042)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4329)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
   at android.view.Choreographer.doCallbacks(Choreographer.java:555)
   at android.view.Choreographer.doFrame(Choreographer.java:525)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
   at android.os.Handler.handleCallback(Handler.java:615)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:5118)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
   at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1