i keep on geting this exeption
05-31 07:42:01.640: E/AndroidRuntime(4133): FATAL EXCEPTION: main
05-31 07:42:01.640: E/AndroidRuntime(4133): Process: com.start.littldeamone, PID: 4133
05-31 07:42:01.640: E/AndroidRuntime(4133): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.start.littldeamone/com.start.littldeamone.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.os.Handler.dispatchMessage(Handler.java:102)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.os.Looper.loop(Looper.java:136)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-31 07:42:01.640: E/AndroidRuntime(4133): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 07:42:01.640: E/AndroidRuntime(4133): at java.lang.reflect.Method.invoke(Method.java:515)
05-31 07:42:01.640: E/AndroidRuntime(4133): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-31 07:42:01.640: E/AndroidRuntime(4133): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-31 07:42:01.640: E/AndroidRuntime(4133): at dalvik.system.NativeStart.main(Native Method)
05-31 07:42:01.640: E/AndroidRuntime(4133): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
05-31 07:42:01.640: E/AndroidRuntime(4133): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.Activity.setContentView(Activity.java:1929)
05-31 07:42:01.640: E/AndroidRuntime(4133): at com.start.littldeamone.MainActivity.onCreate(MainActivity.java:10)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.Activity.performCreate(Activity.java:5231)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-31 07:42:01.640: E/AndroidRuntime(4133): ... 11 more
05-31 07:42:01.640: E/AndroidRuntime(4133): Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.google.android.gms.maps.SupportMapFragment that is not a Fragment
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.Fragment.instantiate(Fragment.java:585)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.Fragment.instantiate(Fragment.java:561)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.app.Activity.onCreateView(Activity.java:4778)
05-31 07:42:01.640: E/AndroidRuntime(4133): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
05-31 07:42:01.640: E/AndroidRuntime(4133): ... 20 more
05-31 07:42:01.640: E/AndroidRuntime(4133): Caused by: java.lang.ClassCastException
05-31 07:42:01.640: E/AndroidRuntime(4133): ... 24 more
i have gone trought all stack overflow solotion and diddnt found the problem chaing from mapactivity to frgment activity and so on... nothing has worked this is my code mainactivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity main xml
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.start.littldeamone"
android:versionCode="1"
android:versionName="1.0" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA58hdExVacurnuB235ojNOJVsF6dH8MMg"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<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="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<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" >
<activity
android:name="com.start.littldeamone.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>
please help!!
First correct this you need to move both <meta-data>
tag under <application>
tag in your manifest.xml
like.
<application>
<activity....>
......
.......
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA58hdExVacurnuB235ojNOJVsF6dH8MMg"/>
</application>
also here your minsdk="8" so you need to change this
public class MainActivity extends Activity
to
public class MainActivity extends FragmentActivity
also your logcat clearly said
05-31 07:42:01.640: E/AndroidRuntime(4133): Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.google.android.gms.maps.SupportMapFragment that is not a Fragment
That means you need to used
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
For more information go to Getting Started Google Maps API V2
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句