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!
Related
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
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
I'm getting the following error trying to start an activity with a Fragment
08-09 13:50:57.070: ERROR/AndroidRuntime(1446): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.zap.imoveis/br.com.zap.imoveis.ui.ResultadoBusca}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
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: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
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.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:133)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:261)
at br.com.zap.imoveis.ui.ResultadoBusca.onCreate(ResultadoBusca.java:54)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
Caused by: java.lang.ClassCastException: br.com.zap.imoveis.ui.ResultadoBuscaMapa cannot be cast to android.app.Fragment
at android.app.Fragment.instantiate(Fragment.java:577)
at android.app.Fragment.instantiate(Fragment.java:552)
at android.app.Activity.onCreateView(Activity.java:4656)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
... 22 more
Despite of what it says here:
Cannot be cast to android.app.Fragment
I have this error even though my Activity extends from android.support.v4.app.FragmentActivity
Unfortunately, error messages some times are very misleading. I've almost rebuilt my application to find out that during a refactor I have accidentally deleted this line o code
super.onCreate(savedInstanceState);
on the onCreate method of my activity.
I have a project that uses the GoogleMaps API, and the support library for Fragments. I have a working map in one activity already, so I know that the API and library are all set up right. I am trying to add a map in a fragment as part of a new activity.
The activity extends an android.support.v4.app.FragmentActivity, and the xml file contains:
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="250dp"
android:name="com.google.android.gms.maps.SupportMapFragment" />
But when I run I get the error:
01-20 11:58:31.535: ERROR/AndroidRuntime(5389): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
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.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at android.app.Activity.setContentView(Activity.java:1835)
at com.yedidyak.gpsalarm.AddAlarm.onCreate(AddAlarm.java:19)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
All the information I can find about this error is about not having the google-play-lib properly installed both as a jar and an imported module, but I have that done - and a working map in another activity.
Any ideas?
You have to reference google play services library instead of adding jar and map_attrs.xml (and other files, like strings.xml) to your project.
If you do, you also might have deleted res/values/map_attrs.xml by accident.
I'm using ActionBarSherlock and customized style for it:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:textColor="#color/grey"
android:id="#+id/bar_title"
style="#style/Text.Medium">
</TextView>
</LinearLayout>
View mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom, null);
getSupportActionBar().setCustomView(mActionBarView);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
In my activity I am overriding setTitle method:
#Override
public void setTitle(CharSequence title) {
TextView txt = (TextView) findViewById(R.id.bar_title);
txt.setText(title);
}
But when in fragment I call getActivity().setTitle(), variable txt in overrided setTitle equals to null.
What's the problem?
Log:
09-06 18:18:21.807: ERROR/AndroidRuntime(953): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alwx.reader/com.alwx.reader.activity.BookActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
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: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
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.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:119)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:251)
at com.alwx.reader.activity.BookActivity.onCreate(BookActivity.java:19)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
Caused by: java.lang.NullPointerException
at com.alwx.reader.activity.BookActivity.setTitle(BookActivity.java:28)
at com.alwx.reader.fragment.BookFragment.onCreateView(BookFragment.java:52)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:846)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1160)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
... 22 more
//this will work
TextView txt = (TextView)mActionBarView. findViewById(R.id.bar_title);
txt.setText(title);
//there is no default style as Text.Medium. you are created change it
style="#android:style/TextAppearance.Medium"