gpt4 book ai didi

java - 不幸的是谷歌地图已经停止

转载 作者:行者123 更新时间:2023-12-01 13:53:39 26 4
gpt4 key购买 nike

我正在尝试使用 Google Maps API v2 构建一个应用程序,并且按照developers.android.com 上的说明进行操作,但仍然出现错误,请帮助我

这是main.java

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.example.googlemap.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MapActivity extends FragmentActivity{

SupportMapFragment mMap;
GoogleMap googleMap;

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

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

googleMap = mMap.getMap();
}
}

Manifest.xml:

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

<permission
android:name="com.example.googlemap.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>

<uses-permission android:name="com.example.googlemap.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"/>

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

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

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.googlemap.MapActivity"
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"/>// i wrote it
</application>

</manifest>

activity_map.xml

<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=".MapActivity" >

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

</RelativeLayout>

最后是我的日志猫:

11-04 11:15:56.034: D/AndroidRuntime(868): Shutting down VM
11-04 11:15:56.074: W/dalvikvm(868): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
11-04 11:15:56.154: E/AndroidRuntime(868): FATAL EXCEPTION: main
11-04 11:15:56.154: E/AndroidRuntime(868): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.googlemap/com.example.googlemap.MapActivity}: java.lang.ClassNotFoundException: com.example.googlemap.MapActivity
11-04 11:15:56.154: E/AndroidRuntime(868): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
11-04 11:15:56.154: E/AndroidRuntime(868): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
11-04 11:15:56.154: E/AndroidRuntime(868): at android.app.ActivityThread.access$600(ActivityThread.java:123)
11-04 11:15:56.154: E/AndroidRuntime(868): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
11-04 11:15:56.154: E/AndroidRuntime(868): at android.os.Handler.dispatchMessage(Handler.java:99)
11-04 11:15:56.154: E/AndroidRuntime(868): at android.os.Looper.loop(Looper.java:137)
11-04 11:15:56.154: E/AndroidRuntime(868): at android.app.ActivityThread.main(ActivityThread.java:4424)
11-04 11:15:56.154: E/AndroidRuntime(868): at java.lang.reflect.Method.invokeNative(Native Method)
11-04 11:15:56.154: E/AndroidRuntime(868): at java.lang.reflect.Method.invoke(Method.java:511)
11-04 11:15:56.154: E/AndroidRuntime(868): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-04 11:15:56.154: E/AndroidRuntime(868): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-04 11:15:56.154: E/AndroidRuntime(868): at dalvik.system.NativeStart.main(Native Method)
11-04 11:15:56.154: E/AndroidRuntime(868): Caused by: java.lang.ClassNotFoundException: com.example.googlemap.MapActivity
11-04 11:15:56.154: E/AndroidRuntime(868):at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-04 11:15:56.154: E/AndroidRuntime(868):at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-04 11:15:56.154: E/AndroidRuntime(868):at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-04 11:15:56.154: E/AndroidRuntime(868):at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
11-04 11:15:56.154: E/AndroidRuntime(868): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
11-04 11:15:56.154: E/AndroidRuntime(868): 11 more
11-04 11:15:56.256: I/dalvikvm(868): threadid=3: reacting to signal 3
11-04 11:15:56.484: I/dalvikvm(868): Wrote stack traces to '/data/anr/traces.txt'
11-04 11:15:56.844: I/dalvikvm(868): threadid=3: reacting to signal 3
11-04 11:15:56.854: I/dalvikvm(868): Wrote stack traces to '/data/anr/traces.txt'
11-04 11:15:57.274: I/dalvikvm(868): threadid=3: reacting to signal 3
11-04 11:15:57.324: I/dalvikvm(868): Wrote stack traces to '/data/anr/traces.txt'

最佳答案

您在 setContentView(R.layout.activity_map); 行中使用 activity_map 但您的 xml 名称是 activity_main 所以您收到错误.

使用 setContentView(R.layout.activity_main); 并解决您的问题。

关于java - 不幸的是谷歌地图已经停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19764822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com