当我尝试切换到屏幕的横向时,我收到错误。横向的XML布局工作得很好,因为我通过强制应用程序以横向方式在 AndoridManifest.xml 中进行测试:
android:screenOrientation="portrait"
以下是来自 LogCat 的日志跟踪:
08-03 09:09:33.660: INFO/WindowManager(71): Setting rotation to 1, animFlags=1
08-03 09:09:33.690: INFO/WindowManager(71): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/1 nav=3 orien=2 layout=17}
08-03 09:09:33.849: INFO/WindowManager(71): onOrientationChanged, rotation changed to 1
08-03 09:09:34.010: DEBUG/StatusBar(71): updateResources
08-03 09:09:34.251: DEBUG/AndroidRuntime(479): Shutting down VM
08-03 09:09:34.251: WARN/dalvikvm(479): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
08-03 09:09:34.251: ERROR/AndroidRuntime(479): Uncaught handler: thread main exiting due to uncaught exception
08-03 09:09:34.280: ERROR/AndroidRuntime(479): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:285)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at android.app.Activity.requestWindowFeature(Activity.java:2561)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at com.news.reader.Home.onConfigurationChanged(Home.java:85)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:3607)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:3673)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1864)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at android.os.Handler.dispatchMessage(Handler.java:99)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at android.os.Looper.loop(Looper.java:123)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at android.app.ActivityThread.main(ActivityThread.java:4203)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at java.lang.reflect.Method.invokeNative(Native Method)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at java.lang.reflect.Method.invoke(Method.java:521)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
08-03 09:09:34.280: ERROR/AndroidRuntime(479): at dalvik.system.NativeStart.main(Native Method)
08-03 09:09:34.299: INFO/Process(71): Sending signal. PID: 479 SIG: 3
08-03 09:09:34.299: INFO/dalvikvm(479): threadid=7: reacting to signal 3
08-03 09:09:34.410: INFO/dalvikvm(479): Wrote stack trace to '/data/anr/traces.txt'
有一个错误,它告诉我在设置布局内容之前应该做些什么。有人可以解释我缺少的东西或重定向,这是解释的。
更新
在我致电requestWindowFeature(Configuration.ORIENTATION_LANDSCAPE);
后,我仍然遇到同样的错误:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.home_landscape);
createUI();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.home_portrait);
createUI();
}
答案 0 :(得分:1)
您已超越异常,因为您必须在任何活动的requestWindowFeature()
之前致电setContentView()
。