I have recently picked up a project from a few months ago. Went to re-open the project and found a few of the following errors:
public void onCreate(Bundle savedInstanceState) {
Gives the error: The method onCreate(Bundle) of type myMain must override or implement a supertype method
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
Gives the errors: The method onCreate(Bundle) is undefined for the type Activity
and The method onCreate(Bundle) is undefined for the type Activity.
@Override
protected void onPause() {
Gives the error: The method onPause() of type myMain must override or implement a supertype method
I have created a new project with identical code for the first section (see code block 2) and do not receive any errors. I am certain it is a small config/code change I cannot pin down that will solve all these problems in one sweep.
Full code is:
package com.myapp.app;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class myMain extends Activity {
MediaPlayer mpSplash;
@Override
// onCreate works like in the activity diagram from tutorial.
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
mpSplash = MediaPlayer.create(this, R.raw.logo_noise);
mpSplash.start();
Thread logoTimer = new Thread()
{
public void run()
{
try{
int logoTimer = 0;
while(logoTimer < 2000)
{
sleep(100);
logoTimer = logoTimer +100;
}
startActivity(new Intent ("com.myapp.app.CLEARSCREEN"));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish(); // shut down class
}
}
};
logoTimer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
mpSplash.release();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
mpSplash.pause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
mpSplash.start();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
}
CODE BLOCK 2
import android.app.Activity;
import android.os.Bundle;
public class myMain extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
I have searched around and found mainly overly complex and unrelated issues such as:
import of android.r
Updating the build path
Re-importing the project
creating new references to classes.
Configuring proguard?
None of the above have seemed to work.
Any help that anyone could provide on this issue would be greatly appreciated.
If your code was working before w/o errors, then it definitely should be working now without errors. I am not sure why you posted all of your code in your post, for this reason…
Make sure you haven’t moved the android SDK folder (
android-sdksby default). This will cause eclipse to throw errors like you are describing, because it won’t be able to find the framework classes such asActivity, etc.This error means that eclipse thinks that
onCreateis not a defined method in theActivityclass. This leads me to believe that your either your eclipse install is outdated, eclipse can’t find the SDK class files, or your eclipse install is just totally messed up. Make sure you have the latest version of the ADT plugin (revision 18). If that doesn’t work then just create a new project… it’s not worth trying to figure out what went wrong if you can just start from scratch.