0

ビューを取得しようとしていますが、null を返し続けます。どうすればそれを見つけることができますか?

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 = (view) .... などで NullPointerException を取得し続けます。

4

2 に答える 2

0
layout = (ViewGroup) findViewById(R.layout.trip_content);
v = (View) layout.findViewById(R.id.bg); //where the error is

上記の2行を以下に置き換えます

LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view view = inflater.inflate(R.layout.R.layout.trip_content,null);
TextView name = (TextView) view.findViewById(R.id.bg);

また、TextView は、ImageView およびその他のコントロールに置き換えることができます。

于 2012-04-05T05:59:11.413 に答える