-1

さて、いくつかのレイアウトとテキストビューでカスタム ビューを作成しました。ビューを動的に作成するオブジェクトを作成しました。ビューを作成し、TextViews を設定するコードを次に示します。

    inflater = (LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.run_info_layout, null);

    TextView infoP, in;
    infoP = (TextView) layout.findViewById(R.id.tvInfoParameter);
    in = (TextView) layout.findViewById(R.id.tvInfo);

    infoP.setText(ip);
    in.setText(i); 

アクティビティでは、このコードを使用してこれらのオブジェクトのいくつかを作成しています....

    runInfo.add(new RunInfoLayout("Final Time", run.getTime(), RunEnding.this));
    runInfo.add(new RunInfoLayout("Distance", Float.toString(run.getDistance()), RunEnding.this));
    runInfo.add(new RunInfoLayout("Started", run.getBTime(), RunEnding.this));
    runInfo.add(new RunInfoLayout("Ended", run.getETime(), RunEnding.this));
    runInfo.add(new RunInfoLayout("Number of laps", Integer.toString(numberOfLaps), RunEnding.this));

ArrayList である runInfo を通過し、ビューを ScrollView に追加するループがあります.....

    for(int x = 0; x < runInfo.size(); x++){
        llRunInfo.addView(runInfo.get(x).getView());
    }

llRunInfo は ScrollView の LinearLayout です。その getView() メソッドは、以前のコードで作成したビューを返すだけです。問題は addView() 行にあります。そこで nullPointerException を取得しています。これがlogcatです....

07-25 12:42:25.223: E/AndroidRuntime(31056): Caused by: java.lang.NullPointerException
07-25 12:42:25.223: E/AndroidRuntime(31056):    at android.view.ViewGroup.addView(ViewGroup.java:3148)
07-25 12:42:25.223: E/AndroidRuntime(31056):    at android.view.ViewGroup.addView(ViewGroup.java:3131)
07-25 12:42:25.223: E/AndroidRuntime(31056):    at com.TBJsoft.runprogress.RunEnding.build(RunEnding.java:55)
4

1 に答える 1