2013-03-05 2 views
0

Google Android지도 API V2를 사용하는 앱을 만들었으며 Google에서 제공하는 가이드의 모든 단계를 따라 갔지만 불행하게도 작동하지 않으며 충돌 할 때마다 충돌합니다. 시작하십시오.Android지도 앱이 올바른 MapView를 찾지 못함

문제는 안드로이드지도 API V2 용 MapView 인 com.google.android.gms.maps.MapView를 찾고 있지 않지만 대신 com.google.android.maps.MapView를 찾고있는 것 같습니다. Android Maps API V1 용 MapView는 무엇이며 어떻게 변경합니까?

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> 
+2

'com.cornboyzmaps.googlemapsA.MainActivity'는 문제가있는 클래스입니다. com.example.name.MainActivity에 대한 코드 목록을 보여줍니다. 앱에 'com.cornboyzmaps.googlemapsA'라는 별도의 패키지가 있는데, 실행하려고하는'MainActivity'라는 별도의 패키지가 포함되어있을 수 있습니까? – CommonsWare

+0

예 실제 패키지의 이름은 com.cornboyzmaps.googlemapsA입니다. (또한 com.example.name.MainActivity도 변경되었습니다. 내 코드가 어떻게 보이는지 정렬하고 너무 바보가되어 버렸음을 보여 주며) 실제로 (그 MainActivity.java 코드는 com.cornboyzmaps.googlemapsA에서 온 것입니다.) – user2125673

+0

여기에 게시 한 내용 중이 오류가 발생하는 것은 분명합니다. 별도의 프로젝트를 만들어 오류를 재현 해보십시오. 가능한 경우 프로젝트 전체를 게시하십시오. 별도의 프로젝트로 오류를 재현 할 수없는 경우 오류 재 표면이나 별도의 프로젝트에 모든 올바른 코드가있을 때까지 점차적으로 별도의 프로젝트를 주 프로젝트와 유사하게 만들어야합니다 (이 경우, 개발을 별도의 프로젝트로 전환하십시오). – CommonsWare

답변

0

setContentView를 사용하여 xml 레이아웃을 정상적으로 팽창 시켰습니까? 지금은 XML 조각에서 단편을 만들려고하는 것처럼 보입니다.

0

activity_main.xml에는 프로그래밍 방식으로 추가 했으므로 맵 조각이 없어야합니다.
내가해야 할 일은 activity_mail.xml을 조각 컨테이너가 될 Framelayout을 포함하도록 변경하는 것입니다. 그래서 예를 들면 :

<?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> 

그 후 MainActivity.java에 당신은 FrameLayout이를 위해 findViewById를하고 MapFragment가 추가해야합니다.
또한 MapView에 대해 오류가 발생하지만 코드에는 오류가없는 것이 이상합니다. 더 많은 코드를 게시 할 수 있습니까?

+0

OP는 내장 된'android.R.id.content''FrameLayout'에 조각을 추가하고 있습니다. 레이아웃 XML 파일이 불필요하다는 것을 의미합니다. – CommonsWare

관련 문제