master/detail actionbar fragments - android

I have found this https://github.com/abidk/android_masterdetail_tab_issue and it is exactly the base for my app, great work from abidk. It executes perfect on tablet and adding more fragments is very easy but on phone it is producing an error: what could be the reason and how to fix it?
D/dalvikvm(3695): Late-enabling CheckJNI
D/AndroidRuntime(3695): Shutting down VM
W/dalvikvm(3695): threadid=1: thread exiting with uncaught exception (group=0x41b192a0)
E/AndroidRuntime(3695): FATAL EXCEPTION: main
E/AndroidRuntime(3695): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.example.masterdetail_tabs/com.example.example.masterdetail_tabs.ItemListActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
E/AndroidRuntime(3695): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
E/AndroidRuntime(3695): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
E/AndroidRuntime(3695): at android.app.ActivityThread.access$700(ActivityThread.java:134)
E/AndroidRuntime(3695): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
E/AndroidRuntime(3695): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(3695): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(3695): at android.app.ActivityThread.main(ActivityThread.java:4867)
E/AndroidRuntime(3695): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(3695): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(3695): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
E/AndroidRuntime(3695): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
E/AndroidRuntime(3695): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(3695): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
E/AndroidRuntime(3695): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
E/AndroidRuntime(3695): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
E/AndroidRuntime(3695): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(3695): at com.example.example.masterdetail_tabs.Tab1Fragment.onCreateView(Tab1Fragment.java:18)
E/AndroidRuntime(3695): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
E/AndroidRuntime(3695): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
E/AndroidRuntime(3695): at android.app.BackStackRecord.run(BackStackRecord.java:635)
E/AndroidRuntime(3695): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1399)
E/AndroidRuntime(3695): at android.app.Activity.performStart(Activity.java:5056)
E/AndroidRuntime(3695): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2065)
E/AndroidRuntime(3695): ... 11 more
E/AndroidRuntime(3695): Caused by: java.lang.ClassCastException: com.example.example.masterdetail_tabs.ItemListFragment cannot be cast to android.support.v4.app.Fragment
E/AndroidRuntime(3695): at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
E/AndroidRuntime(3695): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
E/AndroidRuntime(3695): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
E/AndroidRuntime(3695): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
E/AndroidRuntime(3695): ... 20 more
I/Process(3695): Sending signal. PID: 3695 SIG: 9

It's hard to know for sure without seeing your code but it looks like you inherited or imported the wrong Fragment for either your ItemListFragment or the Activity using it.
Your logcat shows the exception as:
Caused by: java.lang.ClassCastException: com.example.example.masterdetail_tabs.ItemListFragment cannot be cast to android.support.v4.app.Fragment
Check your usages and imports etc
import android.support.v4.app.Fragment;
vs
import android.app.Fragment
Also be mindful of which variants of Activity and Fragment can make use of which types and are compatible with which versions of the API. You should read and follow the official Android tutorial on Fragments for further info and proper usages.

Related

java.lang.VeriryError encountered

Deat developers.
I have made an application but i encounter the following problem:
Occasionally (not always - some times) i get the following error:
java.lang.VerifyError: com/google/example/games/basegameutils/GameHelper
at com.google.example.games.basegameutils.BaseGameActivity.onCreate(BaseGameActivity.java:103)
at development.nk.games.tanc.MainActivity.onCreate(MainActivity.java:97)
at android.app.Activity.performCreate(Activity.java:5047)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
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)
I have looked after this problem and i read that i have to check all Libraries. I did that but the problem still is there.
The class "GameHelper" is a helper class that i use from google play services.
"MainActivity" is the main Activity my app runs. "MainActivity" extends "BaseGameActivity" which uses the "GameHelper" class.
Thank you in advance.

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.

Error: MapFragment cannot be cast to android.support.v4.app.Fragment

First, I watched out here: Start FragmentActivity from Activity and now I have the following problem:
MapsActivity:
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
setUpMapIfNeeded();
}
...
and want to start it out of the MainActivity with:
startActivity(new Intent(this, MapsActivity.class));
The activity is registered in Android Manifest:
<activity android:name="de.xbjoernx.gapp.MapsActivity"></activity>
Error
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.xbjoernx.gapp/de.xbjoernx.gapp.MapsActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5227)
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:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
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:323)
at android.app.Activity.setContentView(Activity.java:1881)
at de.xbjoernx.gapp.MapsActivity.onCreate(MapsActivity.java:19)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
... 11 more
Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
... 20 more
Any suggestions how to fix it?
Thanks so far :)
as you are extending FragmentActivity which indicates you are using Support library v4 compatible with lower version of android. Replace MapFragment with SupportMapFragment inside your xml file. SupportMapFragment is the one to use with the Android Support package. MapFragment is for the native API Level 11 version of fragments.

GoogleMap Support Fragment error

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.

Android AVD Bluetooth Activation Problem

By default Bluetooth is not enabled in Android. But when I go to Setting > Wireless & network and I click on Bluetooth Settings I get the following error:
04-04 11:42:22.492:
WARN/dalvikvm(747): threadid=1: thread
exiting with uncaught exception
(group=0x40014760) FATAL EXCEPTION:
main android.view.InflateException:
Binary XML file line #29: Error
inflating class
java.lang.reflect.Constructor
at android.preference.GenericInflater.createItem(GenericInflater.java:397)
at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
at android.preference.GenericInflater.inflate(GenericInflater.java:326)
at android.preference.GenericInflater.inflate(GenericInflater.java:263)
at android.preference.
PreferenceManager.inflateFromResource(PreferenceManager.java:269)
at android.preference.PreferenceFragment.addPreferencesFromResource(PreferenceFragment.java:271)
at com.android.settings.bluetooth.BluetoothSettings.addPreferencesForActivity(BluetoothSettings.java:53)
at com.android.settings.bluetooth.DeviceListPreferenceFragment.onActivityCreated(DeviceListPreferenceFragment.java:93)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:749)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:921)
at android.app.BackStackRecord.run(BackStackRecord.java:578)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1221)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:375)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:126)
at android.app.ActivityThread.main(ActivityThread.java:3997)
at java.lang.reflect.Method.invokeNative(Native
Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native
Method) 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.preference.GenericInflater.createItem(GenericInflater.java:383)
... 22 more Caused by: java.lang.NullPointerException
at com.android.settings.bluetooth.BluetoothNamePreference.setSummaryToName(BluetoothNamePreference.java:101)
at com.android.settings.bluetooth.BluetoothNamePreference.(BluetoothNamePreference.java:66)
... 25 more
What I'm missing?
Thanks.
You cant setup bluetooth on ANdroid AVD. Please check this link for emulator limitations:
http://developer.android.com/guide/developing/devices/emulator.html

Categories

Resources