0

代码:

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.

4

1 回答 1

0

使用调试器并添加断点,然后您可以按 F6 逐行查看执行情况

于 2014-02-28T15:10:51.920 回答