在Android的活动方法未定义错误 [英] Method undefined error in Android Activity

查看:416
本文介绍了在Android的活动方法未定义错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使基于引导一个简单的Andr​​oid应用程序。我现在用的是code以下,但它给我的几个错误。它抱怨试图重写的onCreate()方法。确切的错误如下。任何人都可以解释什么错误,我想提出?

 包com.bignerdranch.android.geoquiz;

进口android.os.Bundle;

公共类CheatActivity {

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_cheat);
    }

}
 

确切的错误:

 的方法的onCreate(套装)是不确定的Object类型
该方法的setContentView(INT)是未定义的类型CheatActivity
类型CheatActivity的方法的onCreate(捆绑)必须覆盖或实现
超类型的方法
 

解决方案

 进口android.app.Activity;

公共类CheatActivity延伸活动{
 

您应该扩展自Activity类。因为你只是创建新类,而不可以从父类中重写任何方法。

I'm trying to make a simple Android application based on a guide. I am using the code below, but it is giving me several errors. It is complaining while trying to override the onCreate() method. The exact error is below. Can anyone explain what mistake I am making here?

package com.bignerdranch.android.geoquiz;

import android.os.Bundle;

public class CheatActivity {

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

}

The exact errors:

The method onCreate(Bundle) is undefined for the type Object
The method setContentView(int) is undefined for the type CheatActivity
The method onCreate(Bundle) of type CheatActivity must override or implement 
a supertype method  

解决方案

import android.app.Activity;

public class CheatActivity extends Activity {

You should extend from Activity class. Because you are just creating new class without any methods which can be overridden from parent class.

这篇关于在Android的活动方法未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆