2014-02-18 4 views
0

애플리케이션을 개발 했으므로 Google Maps v2가 필요합니다.Google지도 V2에서 클래스 조각을 부 풀리는 중 오류가 발생했습니다.

import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.view.Menu; 
import android.app.Activity; 

public class MapsV2 extends FragmentActivity {  

private GoogleMap mMap; 

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

    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 
    mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
    final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097); 
    Marker ciu = mMap.addMarker(new MarkerOptions() 
           .position(CIU).title("My Office")); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main_page_option_menu, menu); 
    return true; 
    } 
} 

그리고 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="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.SupportMapFragment" 
     android:name="com.app.reminder.MapsV2"/> 

그래서, 내 장치에서 실행할 때 내가있어 오류 메시지 :

02-18 14:20:37.596: E/AndroidRuntime(30383): FATAL EXCEPTION: main 
02-18 14:20:37.596: E/AndroidRuntime(30383): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.reminder/com.app.reminder.MapsV2}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.access$600(ActivityThread.java:140) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.os.Handler.dispatchMessage(Handler.java:99) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.os.Looper.loop(Looper.java:137) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.main(ActivityThread.java:4898) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at java.lang.reflect.Method.invokeNative(Native Method) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at java.lang.reflect.Method.invoke(Method.java:511) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at dalvik.system.NativeStart.main(Native Method) 
02-18 14:20:37.596: E/AndroidRuntime(30383): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.Activity.setContentView(Activity.java:1924) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.app.reminder.MapsV2.onCreate(MapsV2.java:22) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.Activity.performCreate(Activity.java:5206) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) 
02-18 14:20:37.596: E/AndroidRuntime(30383): ... 11 more 
02-18 14:20:37.596: E/AndroidRuntime(30383): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4132500 but found 0. You must have the following declaration within the <application> element:  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.internal.q.v(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.internal.q.u(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.SupportMapFragment$b.eb(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.dynamic.a.a(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.dynamic.a.onInflate(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290) 
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) 
02-18 14:20:37.596: E/AndroidRuntime(30383): ... 20 more 

매니페스트는 다음과 같습니다.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.app.reminder" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="14" 
    android:targetSdkVersion="15" /> 
<permission 
    android:name="com.app.reminder.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature" /> 

<uses-permission android:name="com.app.reminder.permission.MAPS_RECEIVE" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.VIBRATE" /> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 
<application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" 
    android:name="com.app.reminder.InfoManager"> 
    > 
    <activity 
     android:name="SplashScreen" 
     android:theme="@android:style/Theme.NoTitleBar" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

<activity android:name="MapsV2"></activity><uses-library android:name="com.google.android.maps"  
/> 
<uses-library android:name="com.google.android.maps" /> 
    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIzaSyBDtXP5sYucD8z5pjaJFuvt43sLWOGzyuQ" /> 
    <activity android:name="MapsV2"></activity> 
</application> 
</manifest> 

StackOverFlow에서 답변의 모든 옵션을 시도했습니다.

+0

[이 튜토리얼] (http://umut.tekguc.info/en/content/google-android-map-v2-step-step)을 따르시겠습니까? – user2340612

+0

첨부 매니페스트. 예 user2340612, 모든 자습서에서 동일한 오류가 발생했습니다. – Zvi

+0

잘 튜토리얼 내 의견에 좋지 않다, 당신은 (공식적인 하나) (https://developers.google.com/maps/documentation/android/start) – user2340612

답변

1

로그입니다 매우 분명, 당신은 당신의 매니페스트에이 줄을 누락 :

<meta-data 
     android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" /> 

이 행의 끝에서 읽을 수 있듯이 :

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4132500 but found 0. You must have the following declaration within the <application> element:<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 

또한 Google Play 서비스 (버전 13 이상)의 최신 버전을 가져야합니다. Froyo 용 Google Play 서비스, 누가 그 매개 변수를 포함하지 않습니다.

+0

감사합니다 !!! 이것을 추가 한 후에 를 추가해야했습니다. 이제 작동하고 있습니다. Thanks @Adinia – Zvi

+1

LogCat은 친구입니다.주의 깊게 읽으십시오.) – Adinia

1

당신은 당신의 조각 교환이

mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 

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

그는 FragmentActivity를 확장하면 SupportMapFragment가 맞을 것입니다. – Raghunandan

+0

오류가 동일하지만 02-18 14 : 34 : 36.266 : E/AndroidRuntime (948) : \t com.google.android.gms.maps. SupportMapFragment $ b.eb (알 수없는 출처) – Zvi

+0

@ user3323007 필요한 라이브러리를 추가하지 않은 것 같습니다. –

0

으로 교체해야 manifest.xml에서

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

<uses-sdk 
    android:minSdkVersion="14" 
    android:targetSdkVersion="19" /> 
,

활동 클래스

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

GoogleMap gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 
+0

이미 매니페스트에 정의되어 있습니다. – Zvi

+0

다음 단계를 따르세요. 1. 프로젝트를 마우스 오른쪽 버튼으로 클릭하십시오. 2. Android Tool을 선택합니다. 3. Add Support library를 선택합니다. 이 단계는 라이브러리에도 적용됩니다. –

+0

이 단계를 수행 한 후에 프로젝트를 정리하십시오. –

관련 문제