android - FloatingActionButton Unable to start activity ComponentInfo - android

I want to use Floating Action Button in my application ,to do so I got the latest support library 22.2.1 and add the it to my application as a library. I cleaned the project and there was no more errors .
Then I put this code in my xml layout , but when I run my application ,I ran into an error that I couldn't solve it .
This is my xml code :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/ic_action_person" />
</LinearLayout>
</ScrollView>
This is no the whole code ,I've some other views in the linearlayout and at the end i put FloatingActionButton.
When I run my application ,I get this error :
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.karaj.project/com.karaj.project.FistActiivty}: android.view.InflateException: Binary XML file line #301: Error inflating class android.support.design.widget.FloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #301: Error inflating class android.support.design.widget.FloatingActionButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.karaj.project.DrawerActivity.setContentView(DrawerActivity.java:73)
at com.karaj.project.FistActiivty.onCreate(FistActiivty.java:88)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.FloatingActionButton" on path: DexPathList[[zip file "/data/app/com.karaj.persiandesigners-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.karaj.persiandesigners-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
... 20 more
What am I doing wrong ?
thanks

Do not add support library as jar file to your project
add this line to the gradle file
compile 'com.android.support:design:22.2.1'
and update the android support "REPOSITORY"
http://android-developers.blogspot.com/2015/05/android-design-support-library.html

Add dependencies in your project using
compile 'com.melnykov:floatingactionbutton:1.3.0'
and after that sync project

Related

Exception in Facebook Like button for android apps

I have setup correctly the facebook SDK for facebook like button. It works fine on one phone (Android 4.3) but gives an exception on the other (Android 4.4.4)
The exception is as:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.compzets.popopics/com.compzets.popopics.ui.MainPagerActivity}: android.view.InflateException: Binary XML file line #80: Error inflating class com.facebook.widget.LikeView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #80: Error inflating class com.facebook.widget.LikeView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.compzets.popopics.ui.MainPagerActivity.onCreate(MainPagerActivity.java:58)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.widget.LikeView" on path: DexPathList[[zip file "/data/app/com.compzets.popopics-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.compzets.popopics-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
... 22 more
It gives a ClassNotFoundException, I have no clue as to why it happens? And if there is an issue then why it isn't reflected on both phones.
I faced a similar issue some days back and the following solved it:
Removed compile 'com.facebook.android:facebook-android-sdk:3.21.1' from the dependencies in gradle
Synced it
Added the same dependency again
Again Synced it
Hope this works for you as well!

Getting FATAL EXCEPTION in extended calendar

I was initially using the calendar view and that was fine.
i wanted to display my events in the calendar view so i tried extended calendar view library.
When i imported the library project and integrated the code i am getting the following error.
FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #7: Error inflating class provider
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.ithoughtz.sns.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:171)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: android.view.provider
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:552)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
... 19 more
Kindly let me know if i need to post code.
XML for calendar view as follows
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<provider
android:name="com.tyczj.extendedcalendarview.CalendarProvider"
android:authorities="com.tyczj.extendedcalendarview.calendarprovider" />
<com.tyczj.extendedcalendarview.ExtendedCalendarView
android:id="#+id/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
provider is a tag that has to be declared in the AndroidManifast.xml file of your project for declaring ContentProviders and not in the layout file.
provider is not an xml tag that is why your exception stack states the cause to be provider class not found.
right click on project->Build path->configer Build path-> order and export-> checked all option->press OK...
Now try to run your project

Android Time Square Calendar erro at XML

ok guy's.. hellow.. that's my problam:
i'm trying build one Custom CalendarView to Android with Eclipse.. so i'm trying do it with Android Times square.
I import JAR from HERE
so.. whem a put XLM exemple:
<com.squareup.timessquare.CalendarPickerView
android:id="#+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
so whem i try change to Graphical Layout I get the following error, this is at Graphical Layout:
Exception raised during rendering: Color value '16dp' must start with #
Exception details are logged in Window > Show View > Error Log
The following classes could not be instantiated:
- com.squareup.timessquare.CalendarPickerView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
...
java.lang.NumberFormatException: Color value '16dp' must start with #
at com.android.layoutlib.bridge.impl.ResourceHelper.getColor(ResourceHelper.java:72)
at android.content.res.BridgeResources.getColor(BridgeResources.java:182)
at com.squareup.timessquare.CalendarPickerView.<init>(CalendarPickerView.java:101)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(at sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:438)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:190)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
So.. and this is the LogCat
FATAL EXCEPTION: main
Process: com.example.exemplocalendario2, PID: 815
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.exemplocalendario2/com.example.exemplocalendario2.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class com.squareup.timessquare.CalendarPickerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
by: android.view.InflateException: Binary XML file line #12: Error inflating class com.squareup.timessquare.CalendarPickerView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at com.example.exemplocalendario2.MainActivity.onCreate(MainActivity.java:14)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
... 11 more
by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.timessquare.CalendarPickerView" on path: DexPathList[[zip file "/data/app/com.example.exemplocalendario2-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.exemplocalendario2-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
... 21 more
So guy's.. that's my problam.. :/ if some1 can help-me.. ty so much :)

java.lang.OutOfMemoryError ImageView

I have a error "java.lang.OutOfMemoryError" how fix it? (sorry for this bad log format, i don't write many code text)
my activity_main.xml , error this
<ImageView
android:layout_width="350dp"
android:layout_height="700dp"
android:id="#+id/imageViewCosmonaut"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-50dp"
android:src="#drawable/background_cosmonaut"/>
LogCat
05-05 16:04:10.313 2475-2475/com.vlad.genius.game E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vlad.genius.game/com.vlad.genius.game.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class android.widget.ImageView
...
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.widget.ImageView
...
Caused by: java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:800)
at android.content.res.Resources.loadDrawable(Resources.java:2105)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
          com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
            at android.app.Activity.setContentView(Activity.java:1895)
            at com.vlad.genius.game.MainActivity.onCreate(MainActivity.java:23)
        
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
Obviously the bitmap you have assigned to your image view is too large to be loaded in your app space. You have to find an alternative way.
Generally for large bitmaps, it's not a good idea to assign them in the XML. Inflation of the XML happens in the UI thread and loading a large bitmap, even if it does not cause OOM, will cause occasional ANR.
I HIGHLY suggest you to read this article, it gives you very valuable lessons how to deal with images in Android in the right way.

ClassNotFoundException when inflating non-compatibility fragment

My application keeps crashing on launch due to what seems to me to be an odd error. I have included the logcat below as well as the relevant layout but as you can see there is an inflate exception caused by a class not found exception for class android.view.fragment. I am not using compatibility fragments (the app does not support pre-ICS) and so everything is expecting android.app.Fragment. All of the other posts I have been able to find suggest using FragmentActivity but that is not a solution here as we do not use the support library. Does anyone have any insight?
The layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/locations"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Some views here -->
<!-- The line below is line 38 referenced in the LogCat -->
<fragment
android:id="#+id/ad_fragment"
android:name="tenkiv.billing.AdFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
tools:layout="#layout/ad_fragment_view" />
</RelativeLayout>
And the LogCat output:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tenkiv.environment.application/com.tenkiv.environment.application.EnvironmentMainActivity}: android.view.InflateException: Binary XML file line #38: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #38: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.slidingmenu.lib.SlidingMenu.setMenu(SlidingMenu.java:384)
at com.tenkiv.environment.application.EnvironmentMainActivity.onCreate(EnvironmentMainActivity.java:335)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.fragment" on path: /data/app/com.tenkiv.environment.application-2.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:552)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
... 20 more
I am not sure by try giving fully qualified name like this
<fragment android:id="#+id/fragmentDetails"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
class="tenkiv.billing.AdFragment"/>
Please make sure that in your FragmentActivity class you also call the onCreate method from the super class:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
....
}
This problem could be caused by silly things like typos or strange invisible characters getting injected in your xml tags. In my case, the cause was a typo in my "fragment" opening tag. I had "frsgment" instead and of course Android Studio didn't raise a flag. It took me a while to figure out. Not good!

Categories

Resources