不能真正的设备上运行谷歌地图V2 [英] Can't run google maps v2 on a real device
问题描述
我试图做一个简单的应用程序,显示设备上谷歌地图。我在阿尔卡特OT 990的Android设备运行它(诉2.2.2),但它显示错误消息应用程序已意外停止....然后强制关闭。我相信我做的一切权利,因为我遵循从YouTube的教程,工作的指示。
这是我的code(我已经包括Android的支持库,谷歌Play服务库和的android.jar):
I am trying to make a simple app that shows google maps on my device. I run it in my Alcatel OT 990 android device (v. 2.2.2) but it shows the error message "Application has stopped unexpectedly.... then force close". I believe I'm doing everything right, since i follow the instructions from a youtube tutorial that works. This is my code (I' ve included Android Support Library, Google Play Services Library and android.jar):
清单
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.xristina.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.xristina.maps.permission.MAPS_RECEIVE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.tutorialgooglemaps.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="*************my key here*********************"/>
</application>
main.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"
tools:context=".MainActivity" >
<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"/>
</RelativeLayout>
MainActivity.java
MainActivity.java
package com.xristina.maps;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends android.support.v4.app.FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
if (mMap == null) {
mMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
任何想法,请??
Any ideas please??
Ι加入由@BBonDoo建议code和logcat的结果是:
Ι added the code suggested by @BBonDoo and the logcat result was:
02-06 16:59:34.807: W/dalvikvm(2735): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
02-06 16:59:34.817: E/AndroidRuntime(2735): FATAL EXCEPTION: main
02-06 16:59:34.817: E/AndroidRuntime(2735): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.xristina.maps/com.example.tutorialgooglemaps.MainActivity}: java.lang.ClassNotFoundException: com.example.tutorialgooglemaps.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.xristina.maps-2.apk]
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2603)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2697)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2051)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.os.Looper.loop(Looper.java:123)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.main(ActivityThread.java:4645)
02-06 16:59:34.817: E/AndroidRuntime(2735): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 16:59:34.817: E/AndroidRuntime(2735): at java.lang.reflect.Method.invoke(Method.java:521)
02-06 16:59:34.817: E/AndroidRuntime(2735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
02-06 16:59:34.817: E/AndroidRuntime(2735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
02-06 16:59:34.817: E/AndroidRuntime(2735): at dalvik.system.NativeStart.main(Native Method)
02-06 16:59:34.817: E/AndroidRuntime(2735): Caused by: java.lang.ClassNotFoundException: com.example.tutorialgooglemaps.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.xristina.maps-2.apk]
02-06 16:59:34.817: E/AndroidRuntime(2735): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
02-06 16:59:34.817: E/AndroidRuntime(2735): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
02-06 16:59:34.817: E/AndroidRuntime(2735): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2595)
02-06 16:59:34.817: E/AndroidRuntime(2735): ... 11 more
我也不得不说,这code是不包括在我就读于教程
http://www.youtube.com/watch?v=mRnEkP2q4fo 并的 http://www.youtube.com/watch?v=OZRgiwGfvSQ
推荐答案
【答案新] ...添加更新]
您logcat的还是不错的。它意味着如下;
Your Logcat is good. It means as follows;
请看看两张图片,并用正确的匹配您的包名(①)(②)。
Please look into two pictures and match your package name(①) with the correct one(②).
请与您的Java文件的包名清单文件替换包名。
Please replace the package name in the manifest file with the package name in your java file.
这是在你的manifest文件正确code;
It is correct code in your manifest file;
<Activity
android:name="com.xristina.maps.MainActivity"
...
【答案老]
您没写完code足够你MainActivity.java显示谷歌地图。请在下面所示的code,这是基本的code必须以显示谷歌地图基本上是知道您填写code在Android平台:
You did not finish writing the code enough to display Google Maps in your MainActivity.java. Please fill your code with the code as shown in the below, which is the basic code you must know essentially in order to display the Google Maps in Android platform:
public class MianActivity extends android.support.v4.app.FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
if (mMap == null) {
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
这篇关于不能真正的设备上运行谷歌地图V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!