0

Stackoverflow で検索しましたが、なぜ THIS が機能しないのかわかりません。独自の ListView スタイルを作成しようとしましたが、例外が発生しました: FATAL MAIN EXCEPTION. 112 行目にエラーがありました。これはメソッド getView() ですが、表示されません...

これは私のコードです:

public class TimeTable {
        private String subject;
        private String other;

        public TimeTable(String subject, String other) {
            this.subject = subject;
            this.other = other;
        }

        public String getSubject() {
            return subject;
        }
        public void setSubject(String subject) {
            this.subject = subject;
        }
        public String getOther() {
            return other;
        }
        public void setOther(String other) {
            this.other = other;
        }

    }

    public class TimeTableAdapter extends ArrayAdapter<TimeTable> {

        private List<TimeTable> timeList;
        private Context context;

        private class TimeTableHolder {
            public TextView subjectView;
            public TextView otherView;
        }

        public TimeTableAdapter(List<TimeTable> timelist, Context ctx) {
            super(ctx, R.layout.listitem, timelist);
            this.timeList = timelist;
            this.context = ctx;
        }

        public View getView(int position, View convertView, ViewGroup parent) { 
            View v = convertView;

            TimeTableHolder holder = new TimeTableHolder();

            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(R.layout.listitem, parent, false);

                TextView subjv = (TextView) v.findViewById(R.id.subject);
                TextView otherv = (TextView) v.findViewById(R.id.other);


                holder.subjectView = subjv;
                holder.otherView = otherv;

                v.setTag(holder);
            } else {
                holder = (TimeTableHolder) v.getTag();
            }

            TimeTable p = timeList.get(position);
            holder.subjectView.setText(p.getSubject());
            holder.otherView.setText("" + p.getOther());            

            return v;
        }
    }

ログキャット:

03-28 21:16:14.854: E/AndroidRuntime(732): FATAL EXCEPTION: main
03-28 21:16:14.854: E/AndroidRuntime(732): java.lang.NullPointerException
03-28 21:16:14.854: E/AndroidRuntime(732):  at com.blay.canisiusroostersonderbouw.TimeTableActivity$TimeTableAdapter.getView(TimeTableActivity.java:121)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.widget.AbsListView.obtainView(AbsListView.java:2271)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.widget.ListView.onMeasure(ListView.java:1156)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.View.measure(View.java:15172)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.View.measure(View.java:15172)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.View.measure(View.java:15172)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.View.measure(View.java:15172)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-28 21:16:14.854: E/AndroidRuntime(732):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.View.measure(View.java:15172)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.Choreographer.doCallbacks(Choreographer.java:555)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.Choreographer.doFrame(Choreographer.java:525)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.os.Handler.handleCallback(Handler.java:615)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.os.Looper.loop(Looper.java:137)
03-28 21:16:14.854: E/AndroidRuntime(732):  at android.app.ActivityThread.main(ActivityThread.java:4745)
03-28 21:16:14.854: E/AndroidRuntime(732):  at java.lang.reflect.Method.invokeNative(Native Method)
03-28 21:16:14.854: E/AndroidRuntime(732):  at java.lang.reflect.Method.invoke(Method.java:511)
03-28 21:16:14.854: E/AndroidRuntime(732):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-28 21:16:14.854: E/AndroidRuntime(732):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-28 21:16:14.854: E/AndroidRuntime(732):  at dalvik.system.NativeStart.main(Native Method)
4

0 に答える 0