我試圖檢索一個視圖,但它一直返回null,我怎麼找到它?如何從tabhost內部的活動中查找tabhost內的視圖的viewviewid?
public class TripDailyItinerary extends Activity {
ViewGroup layout;
View v;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.html_content);
TextView content = (TextView) findViewById(R.id.htmlContent);
layout = (ViewGroup) findViewById(R.layout.trip_content);
v = (View) layout.findViewById(R.id.bg); //where the error is
JSONObject reservation;
int resNumber = ((MyApp) this.getApplication()).getResNum();
String dailyitinerary = "";
try {
reservation = ((MyApp) this.getApplication()).getJSON().getJSONObject("response").getJSONArray("reservations").getJSONObject(resNumber);
dailyitinerary = reservation.getString("dailyitinerary");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
content.setText(Html.fromHtml(dailyitinerary));
}
}
我保持在V =(視圖)獲取一個NullPointerException ....等
分享你的代碼.. – 2012-04-05 05:25:35
你需要在layout中正確檢查你的viewId。分享代碼並縮短問題描述,因爲它甚至比實際的問題更大。 – Sankalp 2012-04-05 05:31:36
發表了一些代碼... – 2012-04-05 05:33:15