Reputation: 45
i am creating a application with using the google map v2 on a real device but i get a problem and the application force close how to fix this after i read many and many solutions none of them worked with me it is something about the fragment
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<permission
android:name="com.example.permission.MAPS_RECIEVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.permission.MAPS_RECIEVE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyC6Sh22y4wF_tKlrE2MljwZ7Cd9-8V-Nks"/>
<activity
android:name="com.example.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>
</application>
</manifest>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_below="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
package com.example;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_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;
}
}
04-08 02:29:33.500: D/dalvikvm(25400): Late-enabling CheckJNI
04-08 02:29:33.535: D/dalvikvm(25400): Debugger has detached; object registry had 1 entries
04-08 02:29:33.730: D/AndroidRuntime(25400): Shutting down VM
04-08 02:29:33.730: W/dalvikvm(25400): threadid=1: thread exiting with uncaught exception (group=0x40d4b2a0)
04-08 02:29:33.750: E/AndroidRuntime(25400): FATAL EXCEPTION: main
04-08 02:29:33.750: E/AndroidRuntime(25400): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.ActivityThread.access$600(ActivityThread.java:140)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.os.Looper.loop(Looper.java:137)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.ActivityThread.main(ActivityThread.java:4898)
04-08 02:29:33.750: E/AndroidRuntime(25400): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 02:29:33.750: E/AndroidRuntime(25400): at java.lang.reflect.Method.invoke(Method.java:511)
04-08 02:29:33.750: E/AndroidRuntime(25400): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
04-08 02:29:33.750: E/AndroidRuntime(25400): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
04-08 02:29:33.750: E/AndroidRuntime(25400): at dalvik.system.NativeStart.main(Native Method)
04-08 02:29:33.750: E/AndroidRuntime(25400): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-08 02:29:33.750: E/AndroidRuntime(25400): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.Activity.setContentView(Activity.java:1924)
04-08 02:29:33.750: E/AndroidRuntime(25400): at com.example.MainActivity.onCreate(MainActivity.java:12)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.Activity.performCreate(Activity.java:5206)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
04-08 02:29:33.750: E/AndroidRuntime(25400): ... 11 more
04-08 02:29:33.750: E/AndroidRuntime(25400): 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
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.Fragment.instantiate(Fragment.java:584)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.Fragment.instantiate(Fragment.java:552)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.Activity.onCreateView(Activity.java:4849)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-08 02:29:33.750: E/AndroidRuntime(25400): ... 21 more
04-08 02:29:33.750: E/AndroidRuntime(25400): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
04-08 02:29:33.750: E/AndroidRuntime(25400): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-08 02:29:33.750: E/AndroidRuntime(25400): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-08 02:29:33.750: E/AndroidRuntime(25400): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-08 02:29:33.750: E/AndroidRuntime(25400): at android.app.Fragment.instantiate(Fragment.java:574)
04-08 02:29:33.750: E/AndroidRuntime(25400): ... 24 more
Upvotes: 0
Views: 180
Reputation: 41099
Your error here is:
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
which means that basically MapFragment
class could not be found. MapFragment
is part of the google-play-services
library. To use it you need to import the google-play-services
into your workspace
and then reference it from your project, you can reed how it's done in the first 3 steps
of this blog post I wrote:
Upvotes: 1