2012-06-24 31 views
0

林目前在访问Hello Mapview时遇到了一些麻烦,http://developer.android.com/training/tutorials/views/hello-mapview.html,但我认为我做到了这一点。我想在单独的活动中显示地图。谷歌地图在单独的活动导致:java.lang.IllegalStateException:无法执行活动的方法

Map.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<com.google.android.maps.MapView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/mapview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:clickable="true" 
    android:apiKey="working key" 
    /> 

</LinearLayout> 

按钮onclick事件应该显示我的地图

public void showMap(View v){ 

    Intent intent = new Intent(getBaseContext(), GoogleMapsActivity.class); 
    startActivity(intent); 
} 

GoogleMapsActivity.java

public class GoogleMapsActivity extends MapActivity 
{ 
MapView mapView; 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.map); 

    mapView = (MapView) findViewById(R.id.mapview); 
    mapView.setBuiltInZoomControls(true); 
} 

该活动已添加到我的清单中,Google apis包含在其中。如果我将地图放在我的主要活动中,但不在我的GoogleMapsActivity中,则其工作正常。请告诉我在这里错过了什么。

感谢

+0

您已经在这里把整个代码? – Sajmon

+0

@ hawaii.five-0我认为相关的部分。你想看看别的吗? – Johan

+0

哪里例外?在哪一行? – Ran

回答

0

https://developers.google.com/maps/documentation/android/reference/

只有一个MapActivity是每个进程的支持。同时运行的多个MapActivities可能会干扰意想不到的方式。

基本上,您只能有1 MapActivityMapView s只能托管在MapActivity。你想要的基本上是不可能的。

编辑:不确定它会为你工作,但你可以尝试用android:process=":remote"标记你的第二个活动,看看是否有效,但我怀疑它。

编辑:显然有一些混淆。看看https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/MapView。这表明:

一个MapView只能由MapActivity构造(或夸大)。这是因为它依赖于在后台访问网络和文件系统的线程;这些线程必须由MapActivity中的生命周期管理负责。瓷砖缓存在应用程序目录中的文件系统上。缓存是自动管理的,因此您无需对其执行任何操作,并且可以随时将其删除。

我将重新迭代:您无法在任何其他活动中显示MapView。

+1

他只是想在另一个活动中显示地图,他不需要两个'MapActivity'类。 – Ran

+0

谢谢,但正如Ran说的那样。但是我找到了这个问题,在我的清单文件中拼错了我的活动:/ – Johan

+0

啊:你没有任何可用的MapActivity。我以为你有一个工作,不能让另一个工作。 – Femi

0

的问题是在我的清单文件拼写错误,

<activity android:name=".GoogleMapActivity" /> //missing an "s" 
相关问题