我的应用程序正在关闭意外,但这很奇怪,因为我正处于开发阶段,因此该应用程序没有任何特别之处! 我的第一堂课:
package it.mi.action.codmmunicator_2ddecoder;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class Loading extends Activity {
@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.loading);
final int tempodiattesa=3000;
Thread schermataattesa=new Thread(){
int aspetta=0;
@Override
public void run(){
try{
super.run();
while(aspetta<tempodiattesa){
sleep(100);
aspetta+=100;
}
}catch(Exception e){
System.out.println("EXc="+e);
}finally{
startActivity(new Intent(Loading.this,Lettore.class));
finish();
}
}
};
schermataattesa.start();
}
}
和第二个:
package it.mi.action.codmmunicator_2ddecoder;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class Lettore extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.lettore);
}
}
当它进入第二堂课时,就会崩溃。 xml是一个普通的线性布局,上面有图像。
我确定Android清单是对的:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="it.mi.action.codmmunicator_2ddecoder" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA"/>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">
<activity android:name="Loading" android:label="@string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Lettore" android:screenOrientation="portrait" android:label="@string/app_name"></activity>
</application>
</manifest>
如果我让应用程序以Lettore开头就崩溃了。我认为问题出在Lettore.java上,但这很荒谬
有人能帮帮我吗? 看到这是不正常的?这是我的logcat:
06-28 13:41:25.322: D/dalvikvm(403): GC_EXTERNAL_ALLOC freed 51K, 53% free 2552K/5379K, external 716K/1038K, paused 61ms
06-28 13:41:29.353: D/AndroidRuntime(403): Shutting down VM
06-28 13:41:29.353: W/dalvikvm(403): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-28 13:41:29.363: E/AndroidRuntime(403): FATAL EXCEPTION: main
06-28 13:41:29.363: E/AndroidRuntime(403): android.app.SuperNotCalledException: Activity {it.mi.action.codmmunicator_2ddecoder/it.mi.action.codmmunicator_2ddecoder.Lettore} did not call through to super.onCreate()
06-28 13:41:29.363: E/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1613)
06-28 13:41:29.363: E/AndroidRuntime(403): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-28 13:41:29.363: E/AndroidRuntime(403): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-28 13:41:29.363: E/AndroidRuntime(403): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-28 13:41:29.363: E/AndroidRuntime(403): at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 13:41:29.363: E/AndroidRuntime(403): at android.os.Looper.loop(Looper.java:123)
06-28 13:41:29.363: E/AndroidRuntime(403): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-28 13:41:29.363: E/AndroidRuntime(403): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 13:41:29.363: E/AndroidRuntime(403): at java.lang.reflect.Method.invoke(Method.java:507)
06-28 13:41:29.363: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-28 13:41:29.363: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-28 13:41:29.363: E/AndroidRuntime(403): at dalvik.system.NativeStart.main(Native Method)
06-28 13:41:32.083: I/Process(403): Sending signal. PID: 403 SIG: 9
我确定Android清单是对的:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="it.mi.action.codmmunicator_2ddecoder" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA"/>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">
<activity android:name="Loading" android:label="@string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Lettore" android:screenOrientation="portrait" android:label="@string/app_name"></activity>
</application>
</manifest>
如果我让应用程序以Lettore开头就崩溃了。我认为问题出在Lettore.java上,但这很荒谬
答案 0 :(得分:2)
super.onCreate() is missing in Lettore class
...
public void onCreate(Bundle savedInstanceState){
super.onCreate(); //<-----------------------------add this
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.lettore);
}
1 - 确认你是否已将Lettore的条目列入清单。
答案 1 :(得分:2)
将您的代码更改为:
替换finally
块:
finally{
startActivity(new Intent(Loading.this,Lettore.class));
finish();
}
与
finally{
Loading.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Loading.this.startActivity(new Intent(Loading.this,Lettore.class));
finish();
}
});
}
并确保您已将manifestast.xml中的Lettore活动注册为:
<Activity android:name=".Lettore" />
编辑: add super.onCreate(savedInstanceState);在Lettore活动中:
package it.mi.action.codmmunicator_2ddecoder;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class Lettore extends Activity {
@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.lettore);
}
}
答案 2 :(得分:2)
添加
super.onCreate( savedInstanceState );
代码