作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 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/
我们有一个使用 Eclipse 和 Maven 的多模块项目。过去我能让它工作的唯一方法是对项目使用平面布局,其中父模块是其他模块的对等体。这适用于 m2eclipse 和 Subversion。 现
我是一名优秀的程序员,十分优秀!