Adding a button to Google Maps fragment layout [duplicate] - android

This question already has answers here:
How to add buttons at top of map fragment API v2 layout
(4 answers)
Closed 8 years ago.
I want to add a button at the top left corner of the map.
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"
/>
I have tried putting the fragment inside a relative layout, but the app crashes.
I have also seen other proposals, but i am not able to make work any of them.
I only need to put a button on the map.
EDITED:
Text for the exception:
04-20 23:35:18.468: E/AndroidRuntime(7462): FATAL EXCEPTION: main
04-20 23:35:18.468: E/AndroidRuntime(7462): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.solinpromex.vivegrancanaria/com.solinpromex.vivegrancanaria.Empresas_Mapa}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.os.Looper.loop(Looper.java:137)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-20 23:35:18.468: E/AndroidRuntime(7462): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 23:35:18.468: E/AndroidRuntime(7462): at java.lang.reflect.Method.invoke(Method.java:511)
04-20 23:35:18.468: E/AndroidRuntime(7462): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-20 23:35:18.468: E/AndroidRuntime(7462): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-20 23:35:18.468: E/AndroidRuntime(7462): at dalvik.system.NativeStart.main(Native Method)
04-20 23:35:18.468: E/AndroidRuntime(7462): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-20 23:35:18.468: E/AndroidRuntime(7462): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.Activity.setContentView(Activity.java:1881)
04-20 23:35:18.468: E/AndroidRuntime(7462): at com.solinpromex.vivegrancanaria.Empresas_Mapa.onCreate(Empresas_Mapa.java:47)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.Activity.performCreate(Activity.java:5104)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-20 23:35:18.468: E/AndroidRuntime(7462): ... 11 more
04-20 23:35:18.468: E/AndroidRuntime(7462): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.Fragment.instantiate(Fragment.java:585)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.Fragment.instantiate(Fragment.java:560)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.app.Activity.onCreateView(Activity.java:4709)
04-20 23:35:18.468: E/AndroidRuntime(7462): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-20 23:35:18.468: E/AndroidRuntime(7462): ... 21 more

I bet here is your problem:
Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
Try declaring SupportMapFragment in your xml instead of MapFragment. And also check that your Activity class extends FragmentActivity

Related

Genymotion is crashing when I search my current location but when I run the same app in my mobile it is sucessfully running

04-20 07:50:39.793: E/AndroidRuntime(1983): FATAL EXCEPTION: main
04-20 07:50:39.793: E/AndroidRuntime(1983): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.LocationSearch}: java.lang.NullPointerException
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.os.Looper.loop(Looper.java:137)
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.app.ActivityThread.main(ActivityThread.java:5103)
04-20 07:50:39.793: E/AndroidRuntime(1983): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 07:50:39.793: E/AndroidRuntime(1983): at java.lang.reflect.Method.invoke(Method.java:525)
04-20 07:50:39.793: E/AndroidRuntime(1983): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
04-20 07:50:39.793: E/AndroidRuntime(1983): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-20 07:50:39.793: E/AndroidRuntime(1983): at dalvik.system.NativeStart.main(Native Method)
04-20 07:50:39.793: E/AndroidRuntime(1983): Caused by: java.lang.NullPointerException
04-20 07:50:39.793: E/AndroidRuntime(1983): at com.example.googlemap.LocationSearch.onCreate(LocationSearch.java:95)
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.app.Activity.performCreate(Activity.java:5133)
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-20 07:50:39.793: E/AndroidRuntime(1983): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
04-20 07:50:39.793: E/AndroidRuntime(1983): ... 11 more
and Genymotion is showing error on:
googleMap.setMyLocationEnabled(true);
Even my Genymotion GPS location is ON and set on my current location
and it is running fine on my mobile device.
Your problem is that you are using Google Location Services but you don't have Gapps inside the Genymotion emulator!
Try to follow this tutorial in order to flash'em inside the Genymotion ROM.
Its best practice if you use real device for camera or location based apps.As real devices have different camera features that you can not access on emulator.Same is the case with location based apps that you can not have real locations on emulator and more of that Google keep updating map apis for real devices.

App not finding resources after locale change in Android

I am working on a project which requires on the fly language changes. I am attempting to set the desired Locale but as soon as I do, the app crashes complaining that it cannot find Resources (things like R.layout.* R.drawable.*)
This is the code I am using to set the new Locale:
String languageToLoad = "es";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
Edit: added log
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.flavorburst.mcdonalds/com.flavorburst.mcdonalds.MyActivity}: android.view.InflateException: Binary XML file line #25: 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 #25: 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:270)
at android.app.Activity.setContentView(Activity.java:1881)
at com.flavorburst.mcdonalds.MyActivity.onCreate(MyActivity.java:106)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
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.content.res.Resources$NotFoundException: String array resource ID #0x7f08001e
at android.content.res.Resources.getStringArray(Resources.java:451)
at com.flavorburst.mcdonalds.NavigationDrawerFragment.onCreate(NavigationDrawerFragment.java:91)
at android.app.Fragment.performCreate(Fragment.java:1673)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:854)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1137)
at android.app.Activity.onCreateView(Activity.java:4717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
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:270)
at android.app.Activity.setContentView(Activity.java:1881)
at com.flavorburst.application.MyActivity.onCreate(MyActivity.java:106)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
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)
This error:
Caused by: android.content.res.Resources$NotFoundException: String array resource ID #0x7f08001e at android.content.res.Resources.getStringArray(Resources.java:451) at com.flavorburst.mcdonalds.NavigationDrawerFragment
refers to a string array that you have defined in one of your XML files, but you forgot to create the string array value in /values/array.xml. For example, in one of your XML files, you may have specified a string array value of "arrayNames", but you forgot to declare it in /values/array.xml like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="arrayNames"/>
</resources>
So, at runtime, the compiler will complain that it cannot find "arrayNames" in /values/array.xml. Hence, the error you got when you run your app.
Have you tried to clean and rebuild your project? If you are using eclipse got to Project -> Clean. And then build again. If you are using Android Studio and gradle, type the following command line on a terminal:
./gradlew clean
or
use the Build -> Rebuild Project

Why does my app force closes after adding a Relativelayout to a DrawerLayout in android?

I am trying to get a shadow effect to slider Listview. I am trying to put a RelativeLayout with the shadow image beneath the ListView. I have done the following in my xml file but I get force closes with the following errors. Please guide me step by step what to do and where I am going wrong.
My xml file
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
<FrameLayout
android:layout_width="250dp"
android:layout_height="match_parent"
>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#656565"
android:dividerHeight="0.01dp"
android:fadingEdgeLength="10dp"
android:background="#color/list_background"
android:listSelector="#drawable/list_selector"
/>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
error logs:
05-02 17:37:03.256: E/AndroidRuntime(3132): FATAL EXCEPTION: main
05-02 17:37:03.256: E/AndroidRuntime(3132): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.taskmanager/com.example.taskmanager.Profile}: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.os.Looper.loop(Looper.java:137)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-02 17:37:03.256: E/AndroidRuntime(3132): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 17:37:03.256: E/AndroidRuntime(3132): at java.lang.reflect.Method.invoke(Method.java:511)
05-02 17:37:03.256: E/AndroidRuntime(3132): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-02 17:37:03.256: E/AndroidRuntime(3132): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-02 17:37:03.256: E/AndroidRuntime(3132): at dalvik.system.NativeStart.main(Native Method)
05-02 17:37:03.256: E/AndroidRuntime(3132): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:857)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1058)
05-02 17:37:03.256: E/AndroidRuntime(3132): at com.example.taskmanager.Profile.SelectItem(Profile.java:311)
05-02 17:37:03.256: E/AndroidRuntime(3132): at com.example.taskmanager.Profile.onCreate(Profile.java:152)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.app.Activity.performCreate(Activity.java:5104)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-02 17:37:03.256: E/AndroidRuntime(3132): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-02 17:37:03.256: E/AndroidRuntime(3132): ... 11 more
05-02 17:38:42.195: E/Trace(3353): error opening trace file: No such file or directory (2)
05-02 17:38:44.306: E/AndroidRuntime(3353): FATAL EXCEPTION: main
05-02 17:38:44.306: E/AndroidRuntime(3353): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.taskmanager/com.example.taskmanager.Profile}: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.os.Looper.loop(Looper.java:137)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-02 17:38:44.306: E/AndroidRuntime(3353): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 17:38:44.306: E/AndroidRuntime(3353): at java.lang.reflect.Method.invoke(Method.java:511)
05-02 17:38:44.306: E/AndroidRuntime(3353): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-02 17:38:44.306: E/AndroidRuntime(3353): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-02 17:38:44.306: E/AndroidRuntime(3353): at dalvik.system.NativeStart.main(Native Method)
05-02 17:38:44.306: E/AndroidRuntime(3353): Caused by: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:857)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1058)
05-02 17:38:44.306: E/AndroidRuntime(3353): at com.example.taskmanager.Profile.SelectItem(Profile.java:311)
05-02 17:38:44.306: E/AndroidRuntime(3353): at com.example.taskmanager.Profile.onCreate(Profile.java:152)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.app.Activity.performCreate(Activity.java:5104)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-02 17:38:44.306: E/AndroidRuntime(3353): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-02 17:38:44.306: E/AndroidRuntime(3353): ... 11 more
Profile.class
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
final HashMap<String, String> c=db.getAddedContacts();
// Initializing
dataList = new ArrayList<DrawerItem>();
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
TypefaceSpan tp;
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.green));
actionBar.setCustomView(R.layout.actionbars);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));
Apparently you have your listView inside of FrameLayout. If you remove it things will works just fine.
Otherwise set a id to 2nd frameLayout in xml
android:id="#+id/framelayout"
and then get the instance of that FrameLayout
FrameLayout frameLayout = (LinearLayout) findViewById(R.id.frameLayout);
Pass instance of the FrameLayout to mDrawerLayout.closeDrawer(frameLayout);.
Hope this solves the problem.

Spinner on an ActionBar issue on a Dialog Activity

Hi I have an activity that shows a dialog form an standard layout.
android:theme="#android:style/Theme.Holo.Light.Dialog"/>
I was trying to add a simple spinner to the actionbar but I am having issues and error in the line getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST).
When I change my theme to a common activity it works perfect.
This are the errors showed by the logcat:
3114-3114/org.PeteProto E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.PeteProto/org.PeteProto.Detail}: java.lang.NullPointerException
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:5039)
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: java.lang.NullPointerException
at org.PeteProto.Detail.onCreate(Detail.java:30)
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

LogCat. How to trace a bug?

I am new to Android debugging. i read about logCat and DDMS on the functions both have and on filtering.
But, i dont understand how to debug my code with logCat. i classified my logcat by Error. and i got 30 errors relating to all kind of issues, ranging from sound issues to battery issues to main issues...
04-20 06:31:09.982: ERROR/Zygote(33): setreuid() failed. errno: 2
04-20 06:31:16.872: ERROR/Zygote(33): setreuid() failed. errno: 17
04-20 06:31:18.064: ERROR/BatteryService(60): usbOnlinePath not found
04-20 06:31:18.064: ERROR/BatteryService(60): batteryVoltagePath not found
04-20 06:31:18.064: ERROR/BatteryService(60): batteryTemperaturePath not found
04-20 06:31:18.082: ERROR/SurfaceFlinger(60): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
04-20 06:31:23.482: ERROR/EventHub(60): could not get driver version for /dev/input/mouse0, Not a typewriter
04-20 06:31:23.482: ERROR/EventHub(60): could not get driver version for /dev/input/mice, Not a typewriter
04-20 06:31:23.692: ERROR/System(60): Failure starting core service
04-20 06:31:23.692: ERROR/System(60): java.lang.SecurityException
04-20 06:31:23.692: ERROR/System(60): at android.os.BinderProxy.transact(Native Method)
04-20 06:31:23.692: ERROR/System(60): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
04-20 06:31:23.692: ERROR/System(60): at android.os.ServiceManager.addService(ServiceManager.java:72)
04-20 06:31:23.692: ERROR/System(60): at com.android.server.ServerThread.run(SystemServer.java:184)
04-20 06:31:24.602: ERROR/SoundPool(60): error loading /system/media/audio/ui/Effect_Tick.ogg
04-20 06:31:24.602: ERROR/SoundPool(60): error loading /system/media/audio/ui/KeypressStandard.ogg
04-20 06:31:24.602: ERROR/SoundPool(60): error loading /system/media/audio/ui/KeypressSpacebar.ogg
04-20 06:31:24.612: ERROR/SoundPool(60): error loading /system/media/audio/ui/KeypressDelete.ogg
04-20 06:31:24.622: ERROR/SoundPool(60): error loading /system/media/audio/ui/KeypressReturn.ogg
04-20 06:31:26.411: ERROR/ThrottleService(60): Could not open GPS configuration file /etc/gps.conf
04-20 06:31:27.751: ERROR/logwrapper(149): executing /system/bin/tc failed: No such file or directory
04-20 06:31:27.792: ERROR/logwrapper(150): executing /system/bin/tc failed: No such file or directory
04-20 06:31:27.823: ERROR/logwrapper(151): executing /system/bin/tc failed: No such file or directory
04-20 06:31:37.841: ERROR/HierarchicalStateMachine(60): TetherMaster - unhandledMessage: msg.what=3
04-20 06:31:58.767: ERROR/AndroidRuntime(277): FATAL EXCEPTION: main
04-20 06:31:58.767: ERROR/AndroidRuntime(277): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.markana.yamba/com.markana.yamba.StatusActivity1}: java.lang.ClassNotFoundException: com.markana.yamba.StatusActivity1 in loader dalvik.system.PathClassLoader[/data/app/com.markana.yamba-2.apk]
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at android.os.Looper.loop(Looper.java:123)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at dalvik.system.NativeStart.main(Native Method)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): Caused by: java.lang.ClassNotFoundException: com.markana.yamba.StatusActivity1 in loader dalvik.system.PathClassLoader[/data/app/com.markana.yamba-2.apk]
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-20 06:31:58.767: ERROR/AndroidRuntime(277): ... 11 more
04-20 07:30:54.993: ERROR/Zygote(33): setreuid() failed. errno: 2
04-20 07:31:02.125: ERROR/Zygote(33): setreuid() failed. errno: 17
04-20 07:31:03.243: ERROR/BatteryService(59): usbOnlinePath not found
04-20 07:31:03.243: ERROR/BatteryService(59): batteryVoltagePath not found
04-20 07:31:03.243: ERROR/BatteryService(59): batteryTemperaturePath not found
04-20 07:31:03.273: ERROR/SurfaceFlinger(59): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
04-20 07:31:09.004: ERROR/EventHub(59): could not get driver version for /dev/input/mouse0, Not a typewriter
04-20 07:31:09.004: ERROR/EventHub(59): could not get driver version for /dev/input/mice, Not a typewriter
04-20 07:31:09.265: ERROR/System(59): Failure starting core service
04-20 07:31:09.265: ERROR/System(59): java.lang.SecurityException
04-20 07:31:09.265: ERROR/System(59): at android.os.BinderProxy.transact(Native Method)
04-20 07:31:09.265: ERROR/System(59): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
04-20 07:31:09.265: ERROR/System(59): at android.os.ServiceManager.addService(ServiceManager.java:72)
04-20 07:31:09.265: ERROR/System(59): at com.android.server.ServerThread.run(SystemServer.java:184)
04-20 07:31:10.843: ERROR/SoundPool(59): error loading /system/media/audio/ui/Effect_Tick.ogg
04-20 07:31:10.865: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressStandard.ogg
04-20 07:31:10.865: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressSpacebar.ogg
04-20 07:31:10.873: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressDelete.ogg
04-20 07:31:10.884: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressReturn.ogg
04-20 07:31:12.824: ERROR/ThrottleService(59): Could not open GPS configuration file /etc/gps.conf
04-20 07:31:14.294: ERROR/logwrapper(149): executing /system/bin/tc failed: No such file or directory
04-20 07:31:14.364: ERROR/logwrapper(150): executing /system/bin/tc failed: No such file or directory
04-20 07:31:14.403: ERROR/logwrapper(152): executing /system/bin/tc failed: No such file or directory
04-20 07:31:26.859: ERROR/HierarchicalStateMachine(59): TetherMaster - unhandledMessage: msg.what=3
04-20 07:31:49.188: ERROR/AndroidRuntime(298): FATAL EXCEPTION: main
04-20 07:31:49.188: ERROR/AndroidRuntime(298): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.markana.yamba/com.markana.yamba.StatusActivity1}: java.lang.ClassNotFoundException: com.markana.yamba.StatusActivity1 in loader dalvik.system.PathClassLoader[/data/app/com.markana.yamba-1.apk]
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at android.os.Looper.loop(Looper.java:123)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at java.lang.reflect.Method.invoke(Method.java:521)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at dalvik.system.NativeStart.main(Native Method)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): Caused by: java.lang.ClassNotFoundException: com.markana.yamba.StatusActivity1 in loader dalvik.system.PathClassLoader[/data/app/com.markana.yamba-1.apk]
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-20 07:31:49.188: ERROR/AndroidRuntime(298): ... 11 more
04-20 07:33:45.057: ERROR/AndroidRuntime(369): FATAL EXCEPTION: main
04-20 07:33:45.057: ERROR/AndroidRuntime(369): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.markana.yamba/com.markana.yamba.StatusActivity1}: java.lang.ClassNotFoundException: com.markana.yamba.StatusActivity1 in loader dalvik.system.PathClassLoader[/data/app/com.markana.yamba-1.apk]
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at android.os.Looper.loop(Looper.java:123)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at java.lang.reflect.Method.invoke(Method.java:521)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at dalvik.system.NativeStart.main(Native Method)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): Caused by: java.lang.ClassNotFoundException: com.markana.yamba.StatusActivity1 in loader dalvik.system.PathClassLoader[/data/app/com.markana.yamba-1.apk]
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-20 07:33:45.057: ERROR/AndroidRuntime(369): ... 11 more
04-20 07:33:58.677: ERROR/AndroidRuntime(412): FATAL EXCEPTION: main
04-20 07:33:58.677: ERROR/AndroidRuntime(412): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.markana.yamba/com.markana.yamba.StatusActivity1}: java.lang.ClassNotFoundException: com.markana.yamba.StatusActivity1 in loader dalvik.system.PathClassLoader[/data/app/com.markana.yamba-2.apk]
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at android.os.Looper.loop(Looper.java:123)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at java.lang.reflect.Method.invoke(Method.java:521)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at dalvik.system.NativeStart.main(Native Method)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): Caused by: java.lang.ClassNotFoundException: com.markana.yamba.StatusActivity1 in loader dalvik.system.PathClassLoader[/data/app/com.markana.yamba-2.apk]
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-20 07:33:58.677: ERROR/AndroidRuntime(412): ... 11 more
My code in the class is quite simple, i did what the example in Android Orielly book did:
package com.markana.yamba;
import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.TwitterException;
import android.app.Activity;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class StatusActivity2 extends Activity implements OnClickListener{
private static final String TAG= "StatusActivity";
EditText editText;
Button updateButton;
TextView textCount;
Twitter twitter;
/** Called when the activity is first created. */
#SuppressWarnings("deprecation")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.status);
//Finds views
editText =(EditText) findViewById(R.id.editText);
updateButton=(Button) findViewById(R.id.buttonUpdate);
updateButton.setOnClickListener(this);
textCount= (TextView) findViewById(R.id.editText);
textCount.setText(Integer.toString(40));
textCount.setTextColor(Color.GREEN);
// editText.addTextChangedListener(this);
twitter=new Twitter("student","password");
twitter.setAPIRootUrl(("http://yamba.marakana.com/api"));
//added by me
AsyncTask<String, ?, ?> asyn=new PostToTwitter();
asyn.execute("deliver this to twitter");
}
class PostToTwitter extends AsyncTask<String,Integer, String>
{
#Override
protected String doInBackground(String... statuses) {
try{
Twitter.Status status=twitter.updateStatus(statuses[0]);
return status.text;
}
catch(TwitterException e)
{
Log.e(TAG,e.toString());
e.printStackTrace();
return "Failed to post";
}
}
protected void onProgressUpdate(Integer...values)
{
super.onProgressUpdate(values);
}
protected void onPostExecute(String result)
{
Toast.makeText(StatusActivity2.this,result,Toast.LENGTH_LONG).show();
}
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
String status=editText.getText().toString();
new PostToTwitter().execute(status);
Log.d(TAG, "onClick");
}
}
i have no red error marks, nor here nor in the main.xml , string.xml files
How do i trace my bug?
You just read through the output to find
Caused by: java.lang.ClassNotFoundException: com.markana.yamba.StatusActivity1
Which means that this class is missing in the .apk that you've deployed to the device.
Note that your activity is named StatusActivity2 - double check the manifest if that has still StatusActivity1.

Categories

Resources