我正在用netbeans编写一个简单的hello world的android程序,但它返回给我这个错误...我应该做什么才能摆脱这个错误...我是新的并且退出跳到这个。
这是我的代码...
enter code here
package com.google.haha;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
/**
*
* @author abc
*/
public class NewActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
TextView text=new TextView(this);
text.setText("hello");
setContentView(this);
}
}
最佳答案
当你这样做时
setContentView(this);
this 指的是当前类实例,而不是您刚刚创建的 TextView。
尝试:
setContentView(text);
关于java - 方法 Activity.setContentView(int) 不适用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25900441/