Android Studio上的错误(方法不重写其超类的方法)

huangapple go评论75阅读模式
英文:

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;

huangapple
  • 本文由 发表于 2020年9月29日 21:27:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/64120630.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定