我有 2 个活动,一个是 MainActivity,另一个是 ReadActivity。
每当我从 MainActivity 启动 ReadActivity 时,Activity 都会启动,但它什么也没显示,只有 Manifest 文件中的 android:label 值。
在我调查时,我尝试在 ReadActivity 中放置一个日志,但我注意到 OnCreate 方法没有被调用,因为我忘记了覆盖该方法,但是当我将“@Override”放在 OnCreate 方法上方时,我得到了以下错误:
“ReadActivity 类型的方法 OnCreate(Bundle) 必须覆盖或实现超类型方法”。
我不明白这一行有什么问题,我已经检查了很多次,将代码与其他应用程序的代码进行了比较,但我似乎无法覆盖它。谁能帮我?以下是我的项目的代码。
主要活动
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);
}
}
阅读活动
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>
谢谢你。