2016-03-09 48 views
0

我想在沒有支持庫的情況下向Android應用添加工具欄。我試過一個例子 https://gist.github.com/gabrielemariotti/ae63392e1c70bc33af8b 但是當我運行這個例子中,它顯示的應用程序停止工作如何在沒有支持庫的情況下將工具欄添加到Android應用程序?

編輯 登錄貓如下

03-09 11:13:35.969 16807 16807 D dalvikvm          Late-enabling CheckJNI 
03-09 11:13:36.159 16807 16807 D ActivityThread        handleBindApplication:com.mycompany.myapp2 
03-09 11:13:36.479 16807 16807 E dalvikvm          Could not find class 'android.widget.Toolbar', referenced from method com.mycompany.myapp2.MainActivity.onCreate 
03-09 11:13:36.479 16807 16807 W dalvikvm          VFY: unable to resolve check-cast 24 (Landroid/widget/Toolbar;) in Lcom/mycompany/myapp2/MainActivity; 
03-09 11:13:36.499 16807 16807 D dalvikvm          VFY: replacing opcode 0x1f at 0x001a 
03-09 11:13:36.499 16807 16807 I dalvikvm          Failed resolving Lcom/mycompany/myapp2/MainActivity$100000000; interface 23 'Landroid/widget/Toolbar$OnMenuItemClickListener;' 
03-09 11:13:36.499 16807 16807 W dalvikvm          Link of class 'Lcom/mycompany/myapp2/MainActivity$100000000;' failed 
03-09 11:13:36.499 16807 16807 D dalvikvm          DexOpt: unable to opt direct call 0x003f at 0x30 in Lcom/mycompany/myapp2/MainActivity;.onCreate 
03-09 11:13:36.539 16807 16807 W ApplicationPackageManager     getCSCPackageItemText() 
03-09 11:13:36.549 16807 16807 D DisplayManager        DisplayManager() 
03-09 11:13:36.759 16807 16807 D AndroidRuntime        Shutting down VM 
03-09 11:13:36.759 16807 16807 W dalvikvm          threadid=1: thread exiting with uncaught exception (group=0x417bebc0) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        FATAL EXCEPTION: main 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        Process: com.mycompany.myapp2, PID: 16807 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.myapp2/com.mycompany.myapp2.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class Toolbar 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.app.ActivityThread.access$800(ActivityThread.java:166) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.os.Handler.dispatchMessage(Handler.java:102) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.os.Looper.loop(Looper.java:136) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.app.ActivityThread.main(ActivityThread.java:5584) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at java.lang.reflect.Method.invokeNative(Native Method) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at java.lang.reflect.Method.invoke(Method.java:515) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at dalvik.system.NativeStart.main(Native Method) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class Toolbar 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.view.LayoutInflater.rInflate(LayoutInflater.java:762) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.view.LayoutInflater.inflate(LayoutInflater.java:499) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:331) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.app.Activity.setContentView(Activity.java:2018) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at com.mycompany.myapp2.MainActivity.onCreate(MainActivity.java:13) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.app.Activity.performCreate(Activity.java:5442) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        ... 11 more 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.Toolbar" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp2-25.apk"],nativeLibraryDirectories=[/data/app-lib/com.mycompany.myapp2-25, /vendor/lib, /system/lib]] 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at java.lang.ClassLoader.loadClass(ClassLoader.java:497) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at java.lang.ClassLoader.loadClass(ClassLoader.java:457) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.view.LayoutInflater.createView(LayoutInflater.java:566) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:659) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:676) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:701) 
03-09 11:13:36.789 16807 16807 E AndroidRuntime        ... 21 more 
+0

發佈您的logcat。 –

+0

我認爲這會解決您的問題[Android工具欄](http://stackoverflow.com/a/35550809/3959610) – Kushal

+0

您正在測試這個版本的Android? – ianhanniballake

回答

0

只是做一個自定義工具欄,作爲水平線性佈局。並將您的自定義佈局包含在您需要的其他佈局文件中。

相關問題