SOLVED_Android:崩溃使用API的谷歌地图应用程序启动 [英] SOLVED_Android: Crash start application using api google maps
问题描述
你好,我按照此<一个href=\"https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api\" rel=\"nofollow\">https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api要学会使用谷歌地图API。
Hi I'm following this https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api to learn to use Google Map API.
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dude.uniplaces"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.dude.uniplaces.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.dude.uniplaces.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<permission
android:name="com.dude.uniplaces.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.dude.uniplaces.permission.MAPS_RECEIVE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.dude.uniplaces" />
</intent-filter>
</receiver>
<service android:name="com.dude.uniplaces.GCMIntentService" />
<activity
android:name="com.dude.uniplaces.Index"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.dude.uniplaces.Dude"
android:label="dude" >
</activity>
<activity
android:name="com.dude.uniplaces.SendMess"
android:label="sendmess" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBUO0v3_pHsRXfnGyJ68AeZkCUtHINw6OA"/>
</application>
</manifest>
这是主要的活动我的xml文件:
This is my xml file of main activity:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Index" >
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Invia Messaggio"
android:onClick="sendMex" />
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>
这是我的主要活动:
package com.dude.uniplaces;
import static com.dude.uniplaces.CommonUtilities.DISPLAY_MESSAGE_ACTION;
import static com.dude.uniplaces.CommonUtilities.EXTRA_MESSAGE;
import static com.dude.uniplaces.CommonUtilities.SENDER_ID;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Toast;
import com.google.android.gcm.GCMRegistrar;
public class Index extends Activity {
ProgressDialog progressBar;
AsyncTask<Void, Void, Void> mRegisterTask;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.index);
// Phone is ready
GCMRegistrar.checkDevice(this);
// Checking Manifest
GCMRegistrar.checkManifest(this);
registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));
// Ottieni il Registration ID
final String regId = GCMRegistrar.getRegistrationId(this);
// Controllo se sono registrato
if (regId.equals("")) {
// Mi registro
GCMRegistrar.register(this, SENDER_ID);
} else {
// Sono registrato
if (!GCMRegistrar.isRegisteredOnServer(this)) {
// Provo a registrarmi ancora
final Context context = this;
mRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ServerUtilities.register(context, regId);
return null;
}
@Override
protected void onPostExecute(Void result) {
mRegisterTask = null;
}
};
mRegisterTask.execute(null, null, null);
}
}
/* Here I should be registred */
/* Now is time to take gps coordinates */
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
// Check if enabled and if not send user to the GSP settings
// Better solution would be to display a dialog and suggesting to
// go to the settings
if (!enabled) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Map<String, String> params = new HashMap<String, String>();
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
String message="x";
String Id = GCMRegistrar.getRegistrationId(this);
if( location != null)
message = String.format("%1$s \n%2$s \n%3$s",Id,
location.getLongitude(), location.getLatitude()
);
if(location == null )
params.put("one", "BONAA");
else
params.put("one", message);
ServerUtilities su = new ServerUtilities();
su.go("http://unipiapp.altervista.org/cord.php",params);
}
/**
* Ricevo notifica push
* */
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
// Sveglia il telefono se è in stand-by
WakeLocker.acquire(getApplicationContext());
// Visualizza il messaggio
Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG).show();
// Rilascia il wavelocker
WakeLocker.release();
}
};
@Override
protected void onDestroy() {
if (mRegisterTask != null) {
mRegisterTask.cancel(true);
}
try {
unregisterReceiver(mHandleMessageReceiver);
GCMRegistrar.onDestroy(this);
} catch (Exception e) {
}
super.onDestroy();
}
/* Function call clickin on button */
public void sendMex(View w)
{
Intent intent = new Intent(Index.this, SendMess.class);
startActivity(intent);
}
} /* END CLASS */
我下载了谷歌播放服务,并把它添加到我的工作区,但是当我尝试在我的手机开始应用,它崩溃:
I Downloaded google play service and add it to my workspace, but When I try to start application in my phone, it crashes:
20 05-04:11:24.441:E / AndroidRuntime(11190):致命异常:主要
05-04 20:11:24.441:E / AndroidRuntime(11190):
了java.lang.RuntimeException:无法启动活动
ComponentInfo {com.dude.uniplaces / com.dude.uniplaces.Index}:
android.view.InflateException:二进制XML文件行#19:错误
充气类片段
05-04 20:11:24.441: E/AndroidRuntime(11190): FATAL EXCEPTION: main 05-04 20:11:24.441: E/AndroidRuntime(11190): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dude.uniplaces/com.dude.uniplaces.Index}: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
你能帮助我,好吗?
此致
编辑:
我修改了INDEX.XML你看到了我,然后我说(以为)以正确的方式谷歌库,你可以在武官像看到的,但我还是采取崩溃!
I modified my index.xml as you saw me, then I added (think) in right way google libs as you can see in attache image, but i still take crash!
http://img442.imageshack.us/img442/3539/73174342.png
最后编辑时间:
我解决了增加进口android.support.v4.app.FragmentActivity;
和chancing扩展了FragmentActivity活动
I solved adding import android.support.v4.app.FragmentActivity; and chancing extends Activity with FragmentActivity
感谢所有
推荐答案
您分钟SDK在8
注意:如果您希望在11 API运行应用程序,并降低你需要添加支持库以及
http://developer.android.com/tools/extras/support- library.html
使用此
android:name="com.google.android.gms.maps.SupportMapFragment"
另外,还要确保您已按照从下面的链接中的所有步骤
Also make sure you have followed all the steps from the below link
https://developers.google.com/maps/documentation/android/start
修改
<一个href=\"https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment\" rel=\"nofollow\">https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment
MapFragment为12 API和更高的支持片段的API 11和下
MapFragment for api 12 and higher support fragment for api 11 and lower
另外,还要确保你映射项目引用谷歌播放服务库项目。
Also make sure you map project references google play services library project.
请参阅您的谷歌播放服务在地图中的项目
Refer your google play services in your map project
要检查它的库项目。右键点击您的项目转到属性。选择机器人。检查是否是图书馆被选中。
To check if its a library project. right click on your project goto properties. choose android. check if Is Library is ticked.
要参考在地图项目库项目。
To refer the library project in your map project.
右键点击您的项目转到属性。选择机器人。单击添加,浏览库项目单击添加和确定。请注意下面的绿色打勾。
right click on your project goto properties. choose android. Click add, browse the library project click add and ok. Notice the green tick below.
有关详细信息,请检查下面的链接
For more information check the below link
https://developer.android.com/tools/projects/projects- eclipse.html 。
您也需要,因为你正在使用SupportFragment添加支持库。检查以下链接
You also need to add Support library since you are using SupportFragment. Check the below link
https://developer.android.com/tools/extras/support- library.html
这篇关于SOLVED_Android:崩溃使用API的谷歌地图应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!