【问题标题】:Adding content dynamically to sliding drawer throws NullPointerException将内容动态添加到滑动抽屉会引发 NullPointerException
【发布时间】:2012-03-02 15:50:12
【问题描述】:

代码:

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

【问题讨论】:

  • 哪一行抛出异常?
  • 如何获取行号? :p
  • 你的异常显示了它。

标签: android nullpointerexception slidingdrawer sliding


【解决方案1】:

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

【讨论】:

  • 虽然使用调试器是一种非常有用的技术,但我认为这更适合“一般”评论而不是直接答案。您能否更具体地说明用户应该寻找什么?
  • 不明白你想说什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多