2

我的应用程序使用 android api v2 存在问题,因为它无法启动它只会一直说“不幸的是,app_name 已停止工作。”,我已经按照谷歌发布的指南中的每一步,我也在 StackOverflow 中查找了类似的问题并尝试了解决方案,但不幸的是似乎没有一个有效。所以这就是我向你们寻求帮助的原因。

MainActivity.java

import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.GoogleMap;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

SupportMapFragment mMap;
GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMap = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);

            googleMap = mMap.getMap();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appname.name"
android:versionCode="1"
android:versionName="1.0" >

<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"/>
<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"/>

<permission
     android:name="com.appname.name.permission.MAPS_RECEIVE"
     android:protectionLevel="signature"/>
   <uses-permission android:name="com.appname.name.permission.MAPS_RECEIVE"/>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.appname.name.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="api_key"/>
</application>

</manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity" >

<fragment
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>

LogCat(错误代码)

03-01 20:20:20.258: W/dalvikvm(1989): VFY: unable to resolve check-cast 465 (Lcom/google/android/maps/MapView;) in Lcom/cornboyzmaps/googlemapsA/MainActivity;
03-01 20:20:20.258: D/dalvikvm(1989): VFY: replacing opcode 0x1f at 0x0014
03-01 20:20:20.268: D/dalvikvm(1989): DexOpt: unable to opt direct call 0x0cdf at 0x34 in Lcom/cornboyzmaps/googlemapsA/MainActivity;.onCreate
03-01 20:20:20.458: D/AndroidRuntime(1989): Shutting down VM
03-01 20:20:20.458: W/dalvikvm(1989): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-01 20:20:20.488: E/AndroidRuntime(1989): FATAL EXCEPTION: main
03-01 20:20:20.488: E/AndroidRuntime(1989): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cornboyzmaps.googlemapsA/com.cornboyzmaps.googlemapsA.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.os.Looper.loop(Looper.java:137)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.ActivityThread.main(ActivityThread.java:5041)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at java.lang.reflect.Method.invokeNative(Native Method)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at java.lang.reflect.Method.invoke(Method.java:511)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at dalvik.system.NativeStart.main(Native Method)
03-01 20:20:20.488: E/AndroidRuntime(1989): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.Activity.setContentView(Activity.java:1881)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at com.cornboyzmaps.googlemapsA.MainActivity.onCreate(MainActivity.java:21)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.Activity.performCreate(Activity.java:5104)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-01 20:20:20.488: E/AndroidRuntime(1989):     ... 11 more
03-01 20:20:20.488: E/AndroidRuntime(1989): 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-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.Fragment.instantiate(Fragment.java:592)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.Fragment.instantiate(Fragment.java:560)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.Activity.onCreateView(Activity.java:4709)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-01 20:20:20.488: E/AndroidRuntime(1989):     ... 21 more
03-01 20:20:20.488: E/AndroidRuntime(1989): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: /data/app/com.cornboyzmaps.googlemapsA-2.apk
03-01 20:20:20.488: E/AndroidRuntime(1989):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-01 20:20:20.488: E/AndroidRuntime(1989):     at android.app.Fragment.instantiate(Fragment.java:582)
03-01 20:20:20.488: E/AndroidRuntime(1989):     ... 24 more
03-01 20:25:20.778: I/Process(1989): Sending signal. PID: 1989 SIG: 9
4

1 回答 1

0

我试过运行这个应用程序,它对我来说很好。请记住将项目链接到您的 Google Play 服务项目,如此处所述

您可以从https://github.com/apacha/maps_demo下载它

于 2013-07-11T12:34:15.817 回答