解决方案 »

  1.   

    你这个空间是在fragment的布局里。
    你用mainactivity的context获取textview当然得到一个null。
    需要在fragment里获取并settext。百度千锋,里面有一个不错的视频,而且是4.2的
      

  2.   

    晕了,要 findViewById(R.id.textView),加引号怎么回事
      

  3.   

    额,但是我在fragment里 用findViewById()会有错误爆出,说不是静态方法,小白求解答
      

  4.   

    @Override
    protected void onCreate(Bundle arg0) {
    // TODO Auto-generated method stub
    super.onCreate(arg0);
    setContentView(R.layout.story_activity_layout);

    initView();

    }
    private void initView() { tv = (TextView) findViewById(R.id.tv);
    tv.settext("1123");
      

  5.   

    View layout = inflater.inflate(R.layout.fragment_main, null);
    textView = (TextView) layout.findViewById(R.id.textView);
    textView.setText("1");
    这样写就可以了
      

  6.   

    如果你不需要fragment的话,建议你还是在activity中的activity_main布局中写你的见面。
    如果你一定需要的按照你这样稿的话就应该如下
      

  7.   

    findViewById(R.id.textView)
    不要写引号
      

  8.   

    新手千万不要用fragment做练习。