我正在用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);
这是指当前的类实例,而不是您刚刚创建的TextView。
尝试:
setContentView(text);