讓我先解釋一下我的Android應用程序是由: - 一類從活動延長。在我班上的OnCreate
成員,我嘗試使用從資源文件訪問一個TextView
"MyTextView=(TextView)findViewById(R.id.myTextView);".
訪問我main.xml
文件中描述一個TextView - 其中的TextView被描述爲一個XML文件如下:
<TextView android:name="@+id/myTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/another TextView"/>
在R.java
文件,我可以看到我的TextView已註冊。
我的問題是,當我試圖得到一個手柄上的TextView與findViewById
功能,我得到一個空指針。
這似乎是一個謎我,因爲我寫了另一個應用程序,我能訪問TextViews。我看不出兩個應用程序之間有什麼區別!
你好,
這裏是我的完整佈局文件:
<TextView
android:name="@+id/Titre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Application GPS :"/>
<TextView
android:name="@+id/NombreMaxSatellites"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:name="@+id/NombreSatellites"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello Android from NetBeans"/>
<TextView
android:name="@+id/TempsAcquisition"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello Android from NetBeans"/>
<EditText
android:name="@+id/Texte"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Le texte"/>
<Button android:id="@+id/BoutonTexte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="130dip"
android:layout_marginTop="10dip"
android:text="Terminer"/>
我可以訪問Button
但無論是TextView
也不EditText
。
有什麼想法?
接受一些答案 – 2011-05-04 18:28:39