2016-05-31 9 views
0

Ich weiß wirklich nicht, warum mein Programm nicht ausgeführt wird. Ich glaube, ich habe every hier erklärt: FloatingActionButton example with Support LibraryFloating Action Button throing Fehler

my_layout.xml

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email" /> 

</android.support.design.widget.CoordinatorLayout> 

gradle:

apply plugin: 'com.android.application' 

dependencies { 
    compile fileTree(dir: 'libs', include: '*.jar') 
    compile project(':appcompat_v7') 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    compile 'com.android.support:design:23.1.1' 
} 

android { 
    compileSdkVersion 22 
    buildToolsVersion "22.0.1" 

    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['src'] 
      resources.srcDirs = ['src'] 
      aidl.srcDirs = ['src'] 
      renderscript.srcDirs = ['src'] 
      res.srcDirs = ['res'] 
      assets.srcDirs = ['assets'] 
     } 

     // Move the tests to tests/java, tests/res, etc... 
     instrumentTest.setRoot('tests') 

     // Move the build types to build-types/<type> 
     // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 
     // This moves them out of them default location under src/<type>/... which would 
     // conflict with src/ being used by the main source set. 
     // Adding new build types or product flavors should be accompanied 
     // by a similar customization. 
     debug.setRoot('build-types/debug') 
     release.setRoot('build-types/release') 
    } 

hinzugefügt @ color/floating_action_button_color auf \ AppData \ Local \ Android \ android-sdk \ Plattformen \ android-22 \ data \ res \ values ​​\ themes.xml

aber nach der Ausführung des Programms gibt es immer diesen Fehler:

05-31 15:16:11.792: E/AndroidRuntime(1181): FATAL EXCEPTION: main 
05-31 15:16:11.792: E/AndroidRuntime(1181): Process: com.hppl.accountbook, PID: 1181 
05-31 15:16:11.792: E/AndroidRuntime(1181): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hppl.accountbook/com.hppl.accountbook.MyLayoutActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.app.ActivityThread.access$800(ActivityThread.java:151) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.os.Handler.dispatchMessage(Handler.java:102) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.os.Looper.loop(Looper.java:135) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.app.ActivityThread.main(ActivityThread.java:5257) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at java.lang.reflect.Method.invoke(Native Method) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at java.lang.reflect.Method.invoke(Method.java:372) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
05-31 15:16:11.792: E/AndroidRuntime(1181): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at com.hppl.accountbook.MyLayoutActivity.onCreate(MyLayoutActivity.java:13) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.app.Activity.performCreate(Activity.java:5990) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  ... 10 more 
05-31 15:16:11.792: E/AndroidRuntime(1181): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.CoordinatorLayout" on path: DexPathList[[zip file "/data/app/com.hppl.accountbook-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.view.LayoutInflater.createView(LayoutInflater.java:571) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
05-31 15:16:11.792: E/AndroidRuntime(1181):  ... 19 more 
05-31 15:16:11.792: E/AndroidRuntime(1181):  Suppressed: java.lang.ClassNotFoundException: android.support.design.widget.CoordinatorLayout 
05-31 15:16:11.792: E/AndroidRuntime(1181):   at java.lang.Class.classForName(Native Method) 
05-31 15:16:11.792: E/AndroidRuntime(1181):   at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
05-31 15:16:11.792: E/AndroidRuntime(1181):   at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
05-31 15:16:11.792: E/AndroidRuntime(1181):   at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
05-31 15:16:11.792: E/AndroidRuntime(1181):   ... 22 more 
05-31 15:16:11.792: E/AndroidRuntime(1181):  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

Main:

import android.support.v7.app.ActionBarActivity; 
    import android.os.Bundle; 
    import android.view.Menu; 
    import android.view.MenuItem; 

public class MyLayoutActivity extends ActionBarActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.my_layout); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.my_layout, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 

styles.xml

<resources> 

    <!-- 
     Base application theme, dependent on API level. This theme is replaced 
     by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
    --> 
    <style name="Base.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- 
      Theme customizations available in newer API levels can go in 
      res/values-vXX/styles.xml, while customizations related to 
      backward-compatibility can go here. 
     --> 

    </style> 

    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    </style> 

</resources> 

Jede Idee, wie dieses Problem beheben? Vielen Dank.

+0

könnten Sie den Code für MyLayoutActivity eingeben? – jayeshsolanki93

+0

Fehler ist: Die Klasse "android.support.design.widget.CoordinatorLayout" wurde nicht gefunden. Versuchen Sie, Ihre build.gradle erneut zu synchronisieren und das Projekt neu zu erstellen ... – W0rmH0le

+0

Reinigen Sie Ihr Projekt und starten Sie es neu. – jaibatrik

Antwort

0

ok .... Ich wechselte zu Android Studio ... wow alles funktioniert.

0

Ihre MyLayoutActivity sollte die AppCompactActivity statt ActionBarActivity verlängern.

+0

Sorry, ich habe vergessen, das "my _" zu schreiben ... es ist korrekt in eclipse ... Geändert in AppCompactActivity .. aber es ist immer noch das gleiche Fehler – h0ppel

+0

@ h0ppel Jetzt versuchen, Ihr Projekt neu zu starten und neu zu erstellen – jayeshsolanki93

+0

keine Verbesserung :( – h0ppel

0

Probieren Sie n das Projekt übergeordneten Thema ändern:

<style name="Base.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
+0

noch die Fehler – h0ppel

+0

Fügen Sie sowohl AppCompatActivity als auch Theme.Appcompat zusammen, wie ich bereits erwähnt habe.Aktualisieren Sie auch die neueste Build-Version.Es sollte funktionieren – prat

Verwandte Themen