我对Android很陌生,通过一些教程学习Android。
最近,我遇到了一个很好的网站,它显示了Tabs用法的完美实现。
链接是:http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html
我在Android Studio中复制粘贴完全相同的代码。项目ZIP附在此处:https://drive.google.com/open?id=0B7Q0z2lM1VTRR3JjSXFPQk1vNkE&authuser=0,因为它会包含大量代码。
这是一个非常简单的应用程序,根本没有重大实现。
问题是应用程序在打开时崩溃了。我不知道为什么。它没有理由崩溃,因为我已经通过教程复制了整个代码。
请帮帮我。
日志是:
03-14 07:52:12.702 1814-1814/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.adhish.materialtest3, PID: 1814
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.adhish.materialtest3/com.adhish.materialtest3.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.support.v7.app.ActionBarActivityDelegateBase.setSupportActionBar(ActionBarActivityDelegateBase.java:165)
at android.support.v7.app.ActionBarActivity.setSupportActionBar(ActionBarActivity.java:92)
at com.adhish.materialtest3.MainActivity.onCreate(MainActivity.java:31)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-14 07:52:12.706 499-828/? W/ActivityManager﹕ Force finishing activity com.adhish.materialtest3/.MainActivity
03-14 07:52:13.086 191-191/? E/EGL_emulation﹕ tid 191: eglCreateSyncKHR(1181): error 0x3004 (EGL_BAD_ATTRIBUTE)
03-14 07:52:13.272 499-529/? W/art﹕ Long monitor contention event with owner method=android.graphics.Bitmap com.android.server.wm.WindowManagerService.screenshotApplications(android.os.IBinder, int, int, int, boolean) from WindowManagerService.java:6033 waiters=0 for 245ms
03-14 07:52:13.281 499-555/? W/art﹕ Long monitor contention event with owner method=void com.android.server.am.ActivityManagerService.crashApplication(com.android.server.am.ProcessRecord, android.app.ApplicationErrorReport$CrashInfo) from ActivityManagerService.java:12038 waiters=0 for 544ms
03-14 07:52:13.282 499-499/? W/art﹕ Long monitor contention event with owner method=void com.android.server.am.ActivityManagerService.crashApplication(com.android.server.am.ProcessRecord, android.app.ApplicationErrorReport$CrashInfo) from ActivityManagerService.java:12038 waiters=1 for 540ms
03-14 07:52:13.299 499-524/? W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_ALT_RIGHT, scanCode=100, metaState=META_ALT_ON|META_ALT_RIGHT_ON, flags=0x8, repeatCount=6028, eventTime=370910, downTime=58849, deviceId=1, source=0x301 }
03-14 07:52:13.301 499-524/? W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_ALT_RIGHT, scanCode=100, metaState=META_ALT_ON|META_ALT_RIGHT_ON, flags=0x8, repeatCount=6029, eventTime=372034, downTime=58849, deviceId=1, source=0x301 }
答案 0 :(得分:2)
您可以通过设置
来解决此错误<item name="windowActionBar">false</item>
到你的styles.xml
或者您可以在styles.xml中使用Theme.AppCompat.Light.NoActionBar而不是Theme.AppCompat.Light.DarkActionBar