英文:
Error on Android studio ( Method doesn't override method from its superclass )
问题
package com.example.mahaapptask2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Here we link the btn with the activty in xml file
Button btnHello = findViewById(R.id.btnHello);
btnHello.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
System.out.println("Hello :)");
}
});
}
}
After running the phone simulator, this error occurs:
("Method doesn't override a method from its superclass") so what I have to change?
英文:
package com.example.mahaapptask2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Here we link the btn with the activty in xml file
Button btnHello = findViewById(R.id.btnHello);
btnHello.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
System.out.println("Hello :)");
}
});
}
}
After running the phone simulator this error occurs
( Method doesn't override a method from its superclass )so what I have to change?
答案1
得分: 1
在导入部分添加这行代码:import com.example.mahaapptask2.R;
英文:
Try add this line in import section: import com.example.mahaapptask2.R;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论