1

android2.2でgoogleapiv2を使用したい。

私はすでにそれのためのすべての前提条件の要件を完了しています。

のように:グーグルマップAPIキー。

  1. android-support-v4.jar

  2. google-play-services_lib.jar

  3. google-play-services.jar

このエラーが発生します。

02-26 09:32:04.055: E/AndroidRuntime(334): FATAL EXCEPTION: main
02-26 09:32:04.055: E/AndroidRuntime(334): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mapfragment/com.mapfragment.MainActivity}: java.lang.ClassNotFoundException: com.mapfragment.MainActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.mapfragment-2.apk]
02-26 09:32:04.055: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-26 09:32:04.055: E/AndroidRuntime(334):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-26 09:32:04.055: E/AndroidRuntime(334):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-26 09:32:04.055: E/AndroidRuntime(334):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-26 09:32:04.055: E/AndroidRuntime(334):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-26 09:32:04.055: E/AndroidRuntime(334):  at android.os.Looper.loop(Looper.java:123)
02-26 09:32:04.055: E/AndroidRuntime(334):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-26 09:32:04.055: E/AndroidRuntime(334):  at java.lang.reflect.Method.invokeNative(Native Method)
02-26 09:32:04.055: E/AndroidRuntime(334):  at java.lang.reflect.Method.invoke(Method.java:521)
02-26 09:32:04.055: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-26 09:32:04.055: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-26 09:32:04.055: E/AndroidRuntime(334):  at dalvik.system.NativeStart.main(Native Method)
02-26 09:32:04.055: E/AndroidRuntime(334): Caused by: java.lang.ClassNotFoundException: com.mapfragment.MainActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.mapfragment-2.apk]
02-26 09:32:04.055: E/AndroidRuntime(334):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
02-26 09:32:04.055: E/AndroidRuntime(334):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
02-26 09:32:04.055: E/AndroidRuntime(334):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
02-26 09:32:04.055: E/AndroidRuntime(334):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-26 09:32:04.055: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
02-26 09:32:04.055: E/AndroidRuntime(334):  ... 11 more

私のコード:

MainActivity.java

package com.mapfragment;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.SupportMapFragment;

public class MainActivity extends FragmentActivity {
GoogleMap mapView;
com.google.android.gms.maps.Projection projection;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    FragmentTransaction mTransaction = getSupportFragmentManager()
            .beginTransaction();
    SupportMapFragment mFRaFragment = new MapFragmentD();
    mTransaction.add(R.id.mainl, mFRaFragment);
    mTransaction.commit();

    try {
        MapsInitializer.initialize(this);
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }
}

}

MapFragmentD.java

package com.mapfragment;

import android.app.Activity;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapFragmentD extends SupportMapFragment {

GoogleMap mapView;

@Override
public void onCreate(Bundle arg0) {
    super.onCreate(arg0);
}

@Override
public View onCreateView(LayoutInflater mInflater, ViewGroup arg1,
        Bundle arg2) {
    return super.onCreateView(mInflater, arg1, arg2);
}

@Override
public void onInflate(Activity arg0, AttributeSet arg1, Bundle arg2) {
    super.onInflate(arg0, arg1, arg2);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mapView = getMap();
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.draggable(true);
    markerOptions.position(new LatLng(23.231251f, 71.648437f));
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker());
    mapView.addMarker(markerOptions);
}
}

main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/mainl"
android:layout_height="match_parent" >

<!--     <com.mapfragment.MapFragmentD
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true" /> -->

</FrameLayout>

mapfragments.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:apiKey="0WyiQdWfvE1GnA4nWEz8rX1Ezf-rWMEDShPt5BQ"
    android:clickable="true" />

</RelativeLayout>

google api v2用のいくつかのプログラム私は毎回btを試してみますが、このエラーが発生するたびに発生します。plzはこのエラーを解決するのを手伝ってくれます。

前もって感謝します。

4

1 に答える 1

1

マニフェストに以下を追加する必要があります。

<permission
    android:name="package.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />


<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<uses-permission android:name="package.permission.MAPS_RECEIVE" />

およびアプリケーションタグで

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/map_key" />
于 2013-02-26T04:47:57.713 に答える