gpt4 book ai didi

android - Android 2.2 中的 GOOGlE API V2 问题

转载 作者:行者123 更新时间:2023-11-30 03:45:26 25 4
gpt4 key购买 nike

我想在 android 2.2 中使用 google api v2。

我已经完成了它的所有先决条件。

喜欢:谷歌地图 API key 。

  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

我的代码:

主 Activity .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);
}
}

主.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>

map fragment .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,每次都会出现这个唯一的错误。请帮我解决这个错误..

提前致谢。

最佳答案

您需要在 list 中添加以下内容。

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

关于android - Android 2.2 中的 GOOGlE API V2 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15081237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com