1

목록에서 둘러보기를 선택한 경우 MapView를 시작해야하는 Android 앱에서 작업하고 있습니다.Android Google지도 활동이 시작되지 않음

MainActivity.java :

public class MainActivity extends Activity { 
    public final static String SELECTED_TOUR = "com.me.tourapp.TOUR"; 
    public static TourListAdapter tourListAdapter; 
    private static int selectedTour; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     ... 
    } 

    public void startTour(View view) { 
     Intent intent = new Intent(view.getContext(), TourMapActivity.class); 
     intent.putExtra(SELECTED_TOUR, selectedTour); 
     startActivity(intent); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     ... 
    } 

} 

TourMapActivity.java :

그러나 응용 프로그램은 여기에

내 코드는 ... 내가 텐트를 통해이지도보기를 열려고 할 때마다 충돌 보인다
public class TourMapActivity extends Activity { 

    @SuppressLint("NewApi") 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_tour_map); 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
      getActionBar().setDisplayHomeAsUpEnabled(true); 
     } 

     //check if tour is passed via intent (test): 
     Intent intent = getIntent(); 
     int tourIndex = Integer.parseInt(intent.getStringExtra(MainActivity.SELECTED_TOUR)); 
     Toast.makeText(getApplicationContext(), "the tour: "+ tourIndex, Toast.LENGTH_LONG).show(); 
    } 
} 

activity_tour_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" > 

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

</LinearLayout> 
01 23,516,

및 매니페스트에서 일부 조각 : 나는 또한 자바 빌드 경로에 안드로이드 지원-v4.jar를 포함 설치 및 구글 Play 서비스 수입

<permission 
    android:name="com.me.tourapp.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature"/> 
<uses-permission android:name="com.me.tourapp.permission.MAPS_RECEIVE"/> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<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-library android:name="com.google.android.maps" /> 

<meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIzaSyBqs_*****"/> 

...

난 그냥 돈 ' t 내가 오류를 만들고있어 실마리 ...

편집 하바 : 나는 로그 캣 추가 :

E/AndroidRuntime(28248): FATAL EXCEPTION: main 
E/AndroidRuntime(28248): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hansvn.plaktour/com.hansvn.plaktour.TourMapActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment 
E/AndroidRuntime(28248): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100) 
E/AndroidRuntime(28248): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 
E/AndroidRuntime(28248): at android.app.ActivityThread.access$600(ActivityThread.java:140) 
E/AndroidRuntime(28248): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 
E/AndroidRuntime(28248): at android.os.Handler.dispatchMessage(Handler.java:99) 
E/AndroidRuntime(28248): at android.os.Looper.loop(Looper.java:137) 
E/AndroidRuntime(28248): at android.app.ActivityThread.main(ActivityThread.java:4898) 
E/AndroidRuntime(28248): at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime(28248): at java.lang.reflect.Method.invoke(Method.java:511) 
E/AndroidRuntime(28248): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 
E/AndroidRuntime(28248): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
E/AndroidRuntime(28248): at dalvik.system.NativeStart.main(Native Method) 
E/AndroidRuntime(28248): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment 
E/AndroidRuntime(28248): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
E/AndroidRuntime(28248): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
E/AndroidRuntime(28248): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
E/AndroidRuntime(28248): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
E/AndroidRuntime(28248): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
E/AndroidRuntime(28248): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308) 
E/AndroidRuntime(28248): at android.app.Activity.setContentView(Activity.java:1924) 
E/AndroidRuntime(28248): at com.hansvn.plaktour.TourMapActivity.onCreate(TourMapActivity.java:16) 
E/AndroidRuntime(28248): at android.app.Activity.performCreate(Activity.java:5206) 
E/AndroidRuntime(28248): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083) 
E/AndroidRuntime(28248): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) 
E/AndroidRuntime(28248): ... 11 more 
E/AndroidRuntime(28248): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public 
E/AndroidRuntime(28248): at android.support.v4.app.Fragment.instantiate(Fragment.java:401) 
E/AndroidRuntime(28248): at android.support.v4.app.Fragment.instantiate(Fragment.java:369) 
E/AndroidRuntime(28248): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272) 
E/AndroidRuntime(28248): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) 
E/AndroidRuntime(28248): ... 21 more 
E/AndroidRuntime(28248): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment 
E/AndroidRuntime(28248): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 
E/AndroidRuntime(28248): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
E/AndroidRuntime(28248): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
E/AndroidRuntime(28248): at android.support.v4.app.Fragment.instantiate(Fragment.java:391) 
E/AndroidRuntime(28248): ... 24 more 
+0

는 우리에게 당신을주고있다 로그 캣 오류의 일부를 말할 수 UR TourMapActivity 클래스 – Senthil

+2

에 대한 MapActivity 대신 활동을 확장? – j0hnstew

답변

1

Y Google지도의 API V1을 사용하는 API V2. 따라서 우선 어떤 API를 사용할 것인지 결정하십시오.

다음으로,이 라인을 제거하려면 (이 코드의 가장으로 보이는) API의 V2를 사용하고 있는지 결정하는 경우 :

<uses-library android:name="com.google.android.maps" /> 

그것은 API의 V1의 일부입니다 및 필요하지 않습니다 V2에 있어야합니다.

두 번째로 결정해야 할 것은 응용 프로그램의 레벨이 minAPI 인 것입니다. 당신은 API 수준에 응용 프로그램을 작성하는 경우 < (11)는이 같은, 당신의 XML에 SupportMapFragment을 사용해야합니다

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

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

FragmentActivity를 확장해야합니다 활동이 당신이 을 사용해야 한 경우입니다 FragmentActivity은이 패키지에 포함되어 있기 때문에 the google-support-v4 패키지입니다.

UPDATE : 당신의 로그 캣 출력에서 ​​ : 당신이 매니페스트 파일에서 활동 TourMapActivity를 선언하지 않은 의미하며, 이것이 당신의 오류에 대한 이유입니다

Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.me.tourapp/com.me.tourapp.TourMapActivity}; have you declared this activity in your AndroidManifest.xml? 

.

UPDATE2 : 이 오류 :

Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public. 

SupportMapFragment 클래스를 찾을 수 없다는 사실에서 오류가 말한대로 산출했다. 이 클래스가이 라이브러리의 일부이기 때문에 google-play-services 라이브러리를 올바른 방법으로 참조하지 않았 음을 의미합니다. 어떻게 올바르게 참조하는 나는에 쓴이 블로그 게시물의 처음 3 단계를 참조하십시오 :

Google Map API V2

+0

귀하의 제안을 시도했지만 여전히 작동하지 않습니다 ... 나는 V2를 사용하고 있으므로 manifest에서 태그를 제거했습니다. 프래그먼트를 업데이트하고 FragmentActivity로 클래스를 확장했습니다 ... –

+0

게시 한 logcat에서 Manifest 파일의 Activity TourMapActivity를 선언하지 않았습니다. 이것이 오류의 원인입니다 –

+0

한편 Manifest 파일에 Activity를 추가했습니다. 일식 일식 자동으로 그랬 :하지만 여전히 기쁨 ... 내가 지금 받고있어 오류로 logcat을 업데이 트 –

관련 문제