findViewById in activity issue - android

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"

Related

Missing drawables at runtime

Problem:
My App is missing resources at runtime.
One activity just get killed at startup. (error: color 0x2 could not get converted)
The other activity shows a screen with standard graphics instead of the included ones.
What I did before:
I'm still using Eclipse ADT and wanted to give Android Studio a try.
I already uninstall it to get rid of the runtime issue without success.
Any suggestions?
EDIT:
I think there is a general compiling error as there where no errors in this parts before.
Code 1:
AnimationUtils.loadAnimation(this.context, android.R.anim.fade_in)
Stacktrace 1:
Converting to int: TypedValue{t=0x3/d=0x21b "res/drawable/btn_default.xml" a=1 r=0x1080004}
java.lang.NumberFormatException: Invalid int: "res/drawable/btn_default.xml"
at java.lang.Integer.invalidInt(Integer.java:137)
Converting to int: TypedValue{t=0x3/d=0x21b "res/drawable/btn_default.xml" a=1 r=0x1080004}
at java.lang.Integer.parse(Integer.java:374)
at java.lang.Integer.parseInt(Integer.java:365)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:122)
at android.content.res.TypedArray.getInt(TypedArray.java:255)
at android.view.animation.Animation.<init>(Animation.java:246)
at android.view.animation.AlphaAnimation.<init>(AlphaAnimation.java:40)
at java.lang.NumberFormatException: Invalid int: "res/drawable/btn_default.xml"
at java.lang.Integer.invalidInt(Integer.java:137)
at java.lang.Integer.parse(Integer.java:374)
at java.lang.Integer.parseInt(Integer.java:365)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:122)
at android.content.res.TypedArray.getInt(TypedArray.java:255)
at android.view.animation.Animation.<init>(Animation.java:246)
at android.view.animation.AlphaAnimation.<init>(AlphaAnimation.java:40)
at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:116)
at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:91)
at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:116)
at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:72)
...
Code 2 (MY_activity.java:47):
setContentView(R.layout.MY_activity);
Stacktrace 2:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{my.app/my.app.activity}: android.view.InflateException: Binary XML file line #30: Error inflating class com.android.internal.widget.ActionBarView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
at android.app.ActivityThread.access$700(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
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:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class com.android.internal.widget.ActionBarView
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
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.generateLayout(PhoneWindow.java:3163)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3223)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:312)
at android.app.Activity.setContentView(Activity.java:1901)
at my.app.MY_activity.onCreate(MY_activity.java:47)
at android.app.Activity.performCreate(Activity.java:5047)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 25 more
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.widget.TextView
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.android.internal.widget.ActionBarView.initTitle(ActionBarView.java:831)
at com.android.internal.widget.ActionBarView.setDisplayOptions(ActionBarView.java:632)
at com.android.internal.widget.ActionBarView.<init>(ActionBarView.java:266)
... 28 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 38 more
Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
at android.content.res.TypedArray.getColor(TypedArray.java:326)
at android.widget.TextView.<init>(TextView.java:640)
at android.widget.TextView.<init>(TextView.java:579)
... 41 more
I implemented the new material design like this:
Theme.Material.Light.NoActionBar
The correct form (after including appcompat v7):
Theme.AppCompat.Light.NoActionBar

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

ActionBarView Inflate Crash

I'm getting this crash report from a few users. They are using Samsung SPH-M840 Android version 4.1. The layout I am inflating is a simple FrameLayout with a fragment tag inside it. I am using actionbar-compat.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.customprogrammingsolutions.ShabbosAlarm\/com.cpsolutions.alarmbase.alarm.AlarmMainActivity}: android.view.InflateException: Binary XML file line #30: Error inflating class com.android.internal.widget.ActionBarView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2062)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2087)
at android.app.ActivityThread.access$600(ActivityThread.java:133)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1198)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4777)
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:998)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:765)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class com.android.internal.widget.ActionBarView
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3298)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3358)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:314)
at android.app.Activity.setContentView(Activity.java:1901)
at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:208)
at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:111)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
at com.cpsolutions.alarmbase.alarm.AlarmMainActivity.onCreate(AlarmMainActivity.java:57)
at android.app.Activity.performCreate(Activity.java:5042)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2026)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:593)
... 28 more
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.widget.TextView
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.internal.widget.ActionBarView.initTitle(ActionBarView.java:834)
at com.android.internal.widget.ActionBarView.setDisplayOptions(ActionBarView.java:631)
at com.android.internal.widget.ActionBarView.<init>(ActionBarView.java:265)
... 31 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:593)
... 41 more
Caused by: java.lang.NullPointerException
at android.server.BluetoothPanProfileHandler.createNewTetheringAddressLocked(BluetoothPanProfileHandler.java:332)
at android.text.method.SingleLineTransformationMethod.<init>(SingleLineTransformationMethod.java:33)
at android.text.method.SingleLineTransformationMethod.getInstance(SingleLineTransformationMethod.java:57)
at android.widget.TextView.applySingleLine(TextView.java:7147)
at android.widget.TextView.<init>(TextView.java:1208)
at android.widget.TextView.<init>(TextView.java:606)
... 44 more
EDIT: Here's the xml, and onCreate of AlarmMainActivity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment class="com.cpsolutions.alarmbase.alarm.AlarmListFragment"
android:id="#+id/alarm_list_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
alarmFrag = (AlarmListFragment) getSupportFragmentManager().findFragmentById(R.id.alarm_list_frag);
preferenceFrag = (AlarmPreferenceFragment) getSupportFragmentManager().findFragmentById(R.id.preference_list_frag);
if(preferenceFrag != null) {
isTwoPane = true;
}
}
You have a NullPointerException at
android.server.BluetoothPanProfileHandler.createNewTetheringAddressLocked(BluetoothPanProfileHandler.java:332)
There is an issue with the layout file used in:
com.cpsolutions.alarmbase.alarm.AlarmMainActivity.java
At line 57 there will be a setContentView with the argument R.layout.{insert name here}
Go to res/layout/{insert name here}.xml and fix the issue.
If you need help, post the XML file here.
EDIT:
The error is because it cannot inflate the ActionBarView. Please post the class declaration. (what it inherits or extends)

Class cannot be cast to android.app.Fragment on FragmentActivity

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.

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