代碼:添加內容動態地滑動抽屜引發NullPointerException異常
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
RelativeLayout d= (RelativeLayout)findViewById(R.id.drawer_content);
final LayoutInflater inflate=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView tv = (TextView)inflater.inflate(R.layout.text, null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
tv.setLayoutParams(params);
tv.setText("Appointments");
Log.i("before", "add");
d.addView(tv);
Log.i("after", "add");
}
我一直想在我的滑動抽屜動態添加的內容,但它似乎給我一個NullPointerException
。
哪條線引發異常? – 2012-03-02 15:51:53
我如何得到行號? :p – user1152312 2012-03-03 12:05:56
你的異常顯示它。 – 2012-03-03 12:17:05