无法覆盖活动的OnCreate

时间:2012-05-15 13:41:49

标签: android android-activity override oncreate

我有2个活动,一个是MainActivity,另一个是ReadActivity。

每当我从MainActivity启动ReadActivity时,Activity就会启动,但它什么也没显示,只显示Manifest文件中的android:label值。

在我调查的时候,我尝试了一个Log in ReadActivity但是我注意到没有调用OnCreate方法,因为我忘了覆盖方法但是当我把“@Override”放在OnCreate方法之上时我得到了followong错误:

“ReadActivity类型的OnCreate(Bundle)方法必须覆盖或实现超类型方法”。

我不知道这行是什么问题,我已经多次检查它,将代码与其他应用程序的代码进行比较,但我似乎无法覆盖它。谁能帮我?以下是我项目的代码。

MainActivity

package com.rangga.elearning.ngaji;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity{
    /** Called when the activity is first created. */

    TextView txtLogo, txtVersion;
    Button btnRead, btnIndex, btnAbout;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);

        //Typeface font =  Typeface.createFromAsset(getAssets(), "assets/Schoolbell.ttf");

        txtLogo = (TextView) findViewById(R.id.txtLogo);
        txtVersion = (TextView) findViewById(R.id.txtVersion);
        btnRead = (Button) findViewById(R.id.btnRead);
        btnIndex = (Button) findViewById(R.id.btnIndex);
        btnAbout = (Button) findViewById(R.id.btnAbout);

        /* txtLogo.setTypeface(font);
        txtVersion.setTypeface(font);
        btnRead.setTypeface(font);
        btnIndex.setTypeface(font);
        btnAbout.setTypeface(font); */

        btnRead.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                callIntent();
            }
        });
    }

    public void callIntent(){
        Intent i = new Intent(this, ReadActivity.class);
        startActivity(i);
    }
}

ReadActivity

package com.rangga.elearning.ngaji;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class ReadActivity extends Activity{

    private static String TAG = "ReadActivity";

    @Override
    public void OnCreate(Bundle savedInstanceState){        

        Log.i(TAG, "ReadActivity dimulai");
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.read);          
    }

}

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.rangga.elearning.ngaji"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7"
              android:targetSdkVersion="7"
              android:maxSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name=".ReadActivity"
            android:label="Baca"
            android:screenOrientation="landscape">

        </activity>
    </application>

</manifest>

谢谢。

1 个答案:

答案 0 :(得分:1)

onCreate()不是OnCreate()。此外,您的清单中不包含Intent的{​​{1}}信息。