Insert Google maps into my Android app - android

Hello i will be needing help with my Android app to insert google maps into the app, but every time i do that the app chrashes, and i'm going to insert my code below if there is somebody that can help my to find the problem with the code.
Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maret.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<permission
android:name="com.maret.toilet.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="com.maret.toilet.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.maret.toilet.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="***MY_API_KEY****"/>
</application>
</manifest>
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="My Location"
android:onClick="getLocation"
android:layout_weight="0"
/>
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
Here is my MainActivity.java
package com.maret.maps;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
MY ERROR LOG
03-19 08:41:45.552: E/Trace(641): error opening trace file:
No such file or directory (2)
03-19 08:41:45.861: D/AndroidRuntime(641):
Shutting down VM
03-19 08:41:45.872: W/dalvikvm(641):
threadid=1: thread exiting with uncaught exception (group=0x40a13300)
03-19 08:41:45.891: E/AndroidRuntime(641): FATAL EXCEPTION: main
03-19 08:41:45.891: E/AndroidRuntime(641):
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maret.toilet/com.maret.toilet.MainActivity}: android.view.InflateException:
Binary XML file line #15: Error inflating class fragment
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.os.Looper.loop(Looper.java:137)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.main(ActivityThread.java:4745)
03-19 08:41:45.891: E/AndroidRuntime(641):
at java.lang.reflect.Method.invokeNative(Native Method)
03-19 08:41:45.891: E/AndroidRuntime(641):
at java.lang.reflect.Method.invoke(Method.java:511)
03-19 08:41:45.891: E/AndroidRuntime(641):
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-19 08:41:45.891: E/AndroidRuntime(641):
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-19 08:41:45.891: E/AndroidRuntime(641):
at dalvik.system.NativeStart.main(Native Method)
03-19 08:41:45.891: E/AndroidRuntime(641):
Caused by: android.view.InflateException:
Binary XML file line #15: Error inflating class fragment
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-19 08:41:45.891: E/AndroidRuntime(641):
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Activity.setContentView(Activity.java:1867)
03-19 08:41:45.891: E/AndroidRuntime(641):
at com.maret.toilet.MainActivity.onCreate(MainActivity.java:12)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Activity.performCreate(Activity.java:5008)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-19 08:41:45.891: E/AndroidRuntime(641): ... 11 more
03-19 08:41:45.891: E/AndroidRuntime(641):
Caused by: android.app.Fragment$InstantiationException:
Unable to instantiate fragment com.google.android.gms.maps.MapFragment:
make sure class name exists, is public, and has an empty constructor that is public
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Fragment.instantiate(Fragment.java:584)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Fragment.instantiate(Fragment.java:552)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Activity.onCreateView(Activity.java:4656)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-19 08:41:45.891: E/AndroidRuntime(641): ... 21 more
03-19 08:41:45.891: E/AndroidRuntime(641):
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
03-19 08:41:45.891: E/AndroidRuntime(641):
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-19 08:41:45.891: E/AndroidRuntime(641):
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-19 08:41:45.891: E/AndroidRuntime(641):
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Fragment.instantiate(Fragment.java:574)
03-19 08:41:45.891: E/AndroidRuntime(641): ... 24 more
HERE IS THE NEW LAYOUT AND ACTIVITY
THIS IS main.xml
<?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"
android:orientation="vertical" >
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
* HERE IS MY main.java **
package com.maret.maps;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Main extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
HERE IS THE NEW LOGCAT WHEN THE APP CHRASHES**
03-21 12:23:03.633: E/Trace(958): error opening trace file: No such file or directory (2)
03-21 12:23:04.422: D/AndroidRuntime(958): Shutting down VM
03-21 12:23:04.432: W/dalvikvm(958): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
03-21 12:23:04.452: E/AndroidRuntime(958): FATAL EXCEPTION: main
03-21 12:23:04.452: E/AndroidRuntime(958): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maret.maps/com.maret.maps.Main}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.os.Looper.loop(Looper.java:137)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-21 12:23:04.452: E/AndroidRuntime(958): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 12:23:04.452: E/AndroidRuntime(958): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 12:23:04.452: E/AndroidRuntime(958): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-21 12:23:04.452: E/AndroidRuntime(958): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-21 12:23:04.452: E/AndroidRuntime(958): at dalvik.system.NativeStart.main(Native Method)
03-21 12:23:04.452: E/AndroidRuntime(958): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-21 12:23:04.452: E/AndroidRuntime(958): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-21 12:23:04.452: E/AndroidRuntime(958): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.Activity.setContentView(Activity.java:1867)
03-21 12:23:04.452: E/AndroidRuntime(958): at com.maret.maps.Main.onCreate(Main.java:12)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.Activity.performCreate(Activity.java:5008)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-21 12:23:04.452: E/AndroidRuntime(958): ... 11 more
03-21 12:23:04.452: E/AndroidRuntime(958): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.Fragment.instantiate(Fragment.java:577)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.Fragment.instantiate(Fragment.java:552)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.app.Activity.onCreateView(Activity.java:4656)
03-21 12:23:04.452: E/AndroidRuntime(958): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-21 12:23:04.452: E/AndroidRuntime(958): ... 21 more
03-21 12:23:07.973: I/Process(958): Sending signal. PID: 958 SIG: 9

Here is blog post I wrote on how to create a Map fragment in your application:
Google Maps API V2
From your code it look like your permission are not defined properly, you need to add this:
<permission android:name="com.maret.maps.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.maret.maps.permission.MAPS_RECEIVE"/>
And please add your logcat stack trace at crash moment so we could understand more clearly what the problem is.
UPDATE:
From the error you are receiving:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maret.toilet/com.maret.toilet.MainActivity}: android.view.InflateException:
Binary XML file line #15: Error inflating class fragment
it's seems that you are not referencing the google-play-services library as needed, and this is the reason the fragment can't be inflated. the MapFragment class can't be find.
please check the guide that I posted at the beginning of the answer to see how to make the referencing correctly.

Your application tag in your manifest is missing this line
<uses-library android:name="com.google.android.maps" />
Add that and it should fix the crash
EDIT : This will only work for maps api version 1

Related

java.lang.ClassNotFoundException: Didn't find class "com.millennialmedia.android.VideoPlayer"

I recently moved to MoPub and it all appears to be working well except for I have started getting this exception saying that com.millennialmedia.android.VideoPlayer can not be found. I looked and it isn't on the Millennial jar (I just got the latest from their site). Also my AndroidManifest mentions that class and Android Studio also says it can't be found.
This is what I have there:
<activity android:name="com.millennialmedia.android.MMActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar" android:configChanges="keyboardHidden|orientation|keyboard" />
<activity android:name="com.millennialmedia.android.VideoPlayer" android:configChanges="keyboardHidden|orientation|keyboard" />
On Android Studio the VideoPlayer part is red.
This is the exception I got:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{mypackage/com.millennialmedia.android.VideoPlayer}: java.lang.ClassNotFoundException: Didn't find class "com.millennialmedia.android.VideoPlayer" on path: /data/app/mypackage-1.apk
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
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(Method.java)
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(NativeStart.java)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.millennialmedia.android.VideoPlayer" on path: /data/app/mypackage-1.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.app.Instrumentation.newActivity(Instrumentation.java:1054)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
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(Method.java)
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(NativeStart.java)
Looking at the latest Millennial Media documentation, it looks like
com.millennialmedia.android.VideoPlayer
isn't included. This may be an update that needs to be made.
Alice

Error: android.view.InflateException: Binary XML file line #9: Error inflating class fragment

i have create an Activity with 2 seprat Fragments. In the Run Time the error are these:
Here is the code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<fragment
android:name="com.example.lesson1.Fragment1"
android:id="#+id/activity_fragment1"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent"
/>
<fragment
android:name="com.example.lesson1.Fragment2"
android:id="#+id/activity_fragment2"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent"
/>
</LinearLayout>
public class Myfragments extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_myfragments);
}
}
The errors are :
03-26 11:26:27.808: E/Trace(5610): error opening trace file: No such file or directory (2)
03-26 11:26:31.780: E/AndroidRuntime(5610): FATAL EXCEPTION: main
03-26 11:26:31.780: E/AndroidRuntime(5610): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lesson1/com.example.lesson1.Myfragments}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.os.Looper.loop(Looper.java:137)
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-26 11:26:31.780: E/AndroidRuntime(5610): at java.lang.reflect.Method.invokeNative(Native Method)
03-26 11:26:31.780: E/AndroidRuntime(5610): at java.lang.reflect.Method.invoke(Method.java:511)
03-26 11:26:31.780: E/AndroidRuntime(5610): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-26 11:26:31.780: E/AndroidRuntime(5610): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-26 11:26:31.780: E/AndroidRuntime(5610): at dalvik.system.NativeStart.main(Native Method)
03-26 11:26:31.780: E/AndroidRuntime(5610): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-26 11:26:31.780: E/AndroidRuntime(5610): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-26 11:26:31.780: E/AndroidRuntime(5610): at
.
.
.
my adds are import 'android.support.v4.app.Fragment
You extend Normal Activity. So you need to use import android.app.Fragment.
If you want to use Fragment from Support Library then extend FragmentActivity and use import android.support.v4.app.Fragment.
Fragment Activity is the base class for SupportBased Fragments.

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.

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.

findViewById in activity issue

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"

Categories

Resources