Android地图应用程序没有找到正确的MapView [英] Android Maps app not finding the correct MapView
问题描述
我已经使用谷歌Android地图API V2的应用程序,我按照谷歌提供的指南中的每一步,但它不unfortunely工作,它崩溃每次我试图启动它的时间。
问题似乎就这样,这是不是找com.google.android.gms.maps.MapView这是Android的地图API V2的MapView但它不是查找com.google.android.maps.MapView哪些是为Android地图API V1的MapView,我不知道我该如何改变这种状况?
03-04 00:26:51.274:E / dalvikvm(14369):找不到类的com.google.android.maps.MapView,从法com.cornboyzmaps引用.googlemapsA.MainActivity.onCreate
MainActivity.java
包com.example.name;进口android.os.Bundle;
进口android.support.v4.app.FragmentActivity;
进口com.google.android.gms.maps.SupportMapFragment;公共类MainActivity扩展FragmentActivity { @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); SupportMapFragment片段=新SupportMapFragment();
getSupportFragmentManager()调用BeginTransaction()
。新增(android.R.id.content,片段).commit();
}
}
activity_main.xml中
<?XML版本=1.0编码=UTF-8&GT?;
<片段的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /图
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =match_parent
类=com.google.android.gms.maps.SupportMapFragment/>
的Manifest.xml
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.name
安卓版code =1
机器人:=的versionName1.0> <用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =16/> <许可
机器人:名字=com.example.name.permission.MAPS_RECEIVE
安卓的ProtectionLevel =签名/> <使用许可权的android:NAME =com.example.name.permission.MAPS_RECEIVE/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
<使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/> <应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme
机器人:可调试=真正的>
<活动
机器人:名字=com.example.name.MainActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT; &所述;元数据
机器人:名字=com.google.android.maps.v2.API_KEY
机器人:值=** ** API_KEY/>
< /用途> <用途特征
机器人:glEsVersion =0x00020000
机器人:要求=真/>< /清单>
在activity_main.xml中你不应该有地图碎片,因为你添加编程。结果
我会做的是改变activity_mail.xml包含一个的FrameLayout,这将是片段容器。因此,例如:搜索
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT> <的FrameLayout
机器人:ID =@ + ID / fragment_container
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>
< / RelativeLayout的>
之后,在MainActivity.java你应该findViewbyId为的FrameLayout并添加mapfragment。结果也很奇怪,你得到的MapView一个错误,但没有一个在code。也许你可以发布更多的code的?
I have made an app that uses Google Android Maps API V2 and I have followed every step in the guide provided by Google but it doesn't work unfortunely and it crashes every time I try to start it up.
The issue seem so be that it is not looking for com.google.android.gms.maps.MapView which is the MapView for the Android Maps API V2 but it's instead looking for com.google.android.maps.MapView which is the MapView for the Android Maps API V1 and I'm wondering how do I change that?
03-04 00:26:51.274: E/dalvikvm(14369): Could not find class 'com.google.android.maps.MapView', referenced from method com.cornboyzmaps.googlemapsA.MainActivity.onCreate
MainActivity.java
package com.example.name;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.name"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="com.example.name.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.name.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:debuggable="true" >
<activity
android:name="com.example.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>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</manifest>
In activity_main.xml you shouldn't have a map fragment, since you add it programatically.
What I would do would be to change activity_mail.xml to contain a Framelayout that will be the fragment container. So for example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
after that in MainActivity.java you should findViewbyId for the Framelayout and add the mapfragment.
Also it is strange that you get an error for MapView but there isn't one in your code. Maybe you could post more of your code?
这篇关于Android地图应用程序没有找到正确的MapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!