Java Can';t解析符号“;上下文“;关于简单程序

Java Can';t解析符号“;上下文“;关于简单程序,java,android,Java,Android,我正在尝试创建一个简单的hello world程序来开始Android应用程序开发,但我一直在TextView行上遇到一个错误,该行的上下文为“无法解析符号”上下文 替换: TextView TV=new TextView(context: this); 与: 还请注意,您在onResume()中的代码通常位于onCreate()替换: TextView TV=new TextView(context: this); 与: 另外请注意,您在onResume()中的代码通常位于onCreate

我正在尝试创建一个简单的hello world程序来开始Android应用程序开发,但我一直在TextView行上遇到一个错误,该行的上下文为“无法解析符号”上下文

替换:

TextView TV=new TextView(context: this);
与:

还请注意,您在
onResume()
中的代码通常位于
onCreate()

替换:

TextView TV=new TextView(context: this);
与:


另外请注意,您在
onResume()
中的代码通常位于
onCreate()

中,我认为您可以将代码放在
onCreate
中,而不是
onResume

反正, 替换

TextView TV=new TextView(context: this);


因此,您可以使用您的活动来声明文本视图

我认为您可以将代码放入
onCreate
中,而不是
onResume

反正, 替换

TextView TV=new TextView(context: this);

因此,您可以使用活动来声明TextView

TextView TV=new TextView(context: this);
用这个

TextView TV=new TextView(MainActivity.this);
替换

TextView TV=new TextView(context: this);
用这个

TextView TV=new TextView(MainActivity.this);

TextView TV=new TextView(上下文:this)
行更改为:

TextView TV=new TextView(this);

TextView TV=new TextView(MainActivity.this);

Context context=this;
TextView TV=new TextView(context);
另一种方法是在活动类中使用此代码:

TextView TV=new TextView(getBaseContext());

TextView TV=new TextView(上下文:this)
行更改为:

TextView TV=new TextView(this);

TextView TV=new TextView(MainActivity.this);

Context context=this;
TextView TV=new TextView(context);
另一种方法是在活动类中使用此代码:

TextView TV=new TextView(getBaseContext());

上下文不是必需的。您可以使用以下选项显示所需的文本:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView textView = findViewById(R.id.textview);
    textView.setText("Hello World");
}
只需确保您的TextView具有如下id:

<TextView
    android:id="@+id/textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

上下文不是必需的。您可以使用以下内容显示所需的文本:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView textView = findViewById(R.id.textview);
    textView.setText("Hello World");
}
只需确保您的TextView具有如下id:

<TextView
    android:id="@+id/textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />


Javascript或Java:-)Javascript或Java:-)