ロード時にデータをテキストビューにロードしようとしています。私のアプリはフラグメントを使用し、3 つのタブがあります。最初の 2 つのタブにデータをロードすることはできますが、3 番目のタブにデータをロードしようとするとヌル ポインター例外が発生します。コードは次のとおりです。
public void readAndLoadDataFromFile()
{
String[] fieldNamesInFile = new String[50];
double[] valuesInFile = new double[50];
// read all the data from file
readAllDataFromFile(fieldNamesInFile, valuesInFile);
// Tab 1
double value1 = valuesInFile[Arrays.asList(fieldNamesInFile).indexOf("Field1")];
// copy the data into the fields
((EditText) findViewById(R.id.editText1)).setText(String.valueOf(value1)); // OK
// Tab 2
double value2 = valuesInFile[Arrays.asList(fieldNamesInFile).indexOf("Field2")];
// copy the data into the fields
((EditText) findViewById(R.id.editText2)).setText(String.valueOf(value2)); // OK
// Tab 3
double value3 = valuesInFile[Arrays.asList(fieldNamesInFile).indexOf("Field3")];
// copy the data into the fields
((EditText) findViewById(R.id.editText3)).setText("123"); // null pointer exception
}
タブ 3 のレイアウト XML ファイルは次のとおりです (最初の 2 つのタブは類似しています)。
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Text 3:"
android:clickable="true"
android:gravity="right"
android:layout_weight="2"
android:layout_marginRight="2dp"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="@+id/editText3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:ems="10"
android:text="25"
android:inputType="numberDecimal"
android:textAppearance="?android:attr/textAppearanceSmall" />
</TableRow>
</TableLayout>
</ScrollView>
私は何が欠けていますか?