Android - onPause, onCreate, setContentView not working - method X is undefined for the type myMain
我最近刚从几个月前开始从事一个项目。去重新打开该项目,发现以下一些错误:
1 | public void onCreate(Bundle savedInstanceState) { |
出现错误:类型为myMain的onCreate(Bundle)方法必须重写或实现一个超类型方法
1 2 | super.onCreate(savedInstanceState); setContentView(R.layout.splashscreen); |
给出错误:未为活动类型定义方法onCreate(Bundle)
并且为活动类型未定义onCreate(Bundle)方法。
1 2 | @Override protected void onPause() { |
给出错误:类型为myMain的onPause()方法必须重写或实现一个超类型方法
我已经为第一部分创建了一个具有相同代码的新项目(请参见代码块2),并且没有收到任何错误。我确信这是一个很小的配置/代码更改,我无法确定将一口气解决所有这些问题的方法。
完整的代码是:
包com.myapp.app;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 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(); } |
}
代码块2
1 2 3 4 5 6 7 8 9 10 11 | 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); } } |
我四处搜寻,发现主要是过于复杂和无关的问题,例如:
导入android.r
更新构建路径
重新导入项目
创建对类的新引用。
正在配置proguard?
以上似乎都不起作用。
任何人都可以在此问题上提供的任何帮助将不胜感激。
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.
如果您的代码在没有错误之前就可以正常工作,那么它现在肯定应该可以正常工作而没有错误。我不确定为什么您将所有代码都发布在您的帖子中,因此...
确保您尚未移动android SDK文件夹(默认情况下为
The method
onCreate(Bundle) of typemyMain must override or implement a supertype method.
此错误意味着eclipse认为
如果无法解决问题,请尝试清理项目Project-> clean。我认为问题在于您将编译器设置设置为Java 1.5而不是Java 1.6。
转到Windows->"首选项"->" Java"->"编译器",然后将"编译器符合性级别"更改为1.6