Не знаете, почему это происходит, приложение не показывает ошибок, и я тоже получил ключ, но активность не запускается!Сбой при сбоях Google-карт после успешной установки
Вот мой MapScreen класс:
package com.example.prateekchachra.projectconnecttoastmasters;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
/**
* Created by Prateek Chachra on 5/23/2016.
*/
public class MapScreen extends Activity{
static final LatLng Pos = new LatLng(40, -79);
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
try {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
googleMap.setMyLocationEnabled(true);
googleMap.setTrafficEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
Marker marker = googleMap.addMarker(new MarkerOptions().position(Pos).title("That is my loc"));
} catch(Exception e){
e.printStackTrace();
}
}
}
Вот мой activity_maps.xml файл:
<?xml version = "1.0" encoding = "utf-8" ?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.prateekchachra.projectconnecttoastmasters.MapsActivity" />
</RelativeLayout>
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prateekchachra.projectconnecttoastmasters">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission android:name="com.example.prateekchachra.projectconnecttoastmasters.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="ID" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
</activity>
<activity android:name=".Events"
android:label="Events List">
</activity>
<activity android:name=".FindSlots"
android:label="Find Slots">
</activity>
<activity android:name=".MapScreen"
android:label="Map Main">
</activity>
<activity android:name=".SplashScreen"
android:label="Splash Screen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Logcat Выход:
05 -24 03: 59: 40,867 26851-26851/com.example.prateekchachra.projectconnecttoastmasters E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: не удалось запустить активность ComponentInfo {com.example.prateekchachra.projectconnecttoastmasters/com.example.prateekchachra.projectconnecttoastmasters.MapScreen} : android.view.InflateException: двоичная строка XML-файла # 5: ошибка раздувания фрагмента класса на android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2343) на android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2395) at android.app.ActivityThread.access $ 600 (ActivityThread.java:162) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1364) на android.os.Handler.dispatchMessage (Handler.java:107) на android.os.Looper.loop (Looper.java:194) на android.app.ActivityThread.main (ActivityThread.java:5371) на java .lang.reflect.Method.invokeNative (Native Method) at java.lang.reflect.Method.invoke (Method.java:525) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 833) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:600) at dalvik.system.NativeStart.main (собственный метод) Вызвано: android.view.InflateException: двоичный XML строка файла # 5: ошибка раздувания фрагмента класса на android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:704) на android.view.LayoutInflater.rInflate (LayoutInflater.java:746) на android.view.LayoutInflater.inflate (LayoutInflater.java:489) на android.view.LayoutInflater.inflate (LayoutInflater.java:396) на android.view.LayoutInflater.inflate (LayoutInflater.java:352) на com.android.internal.policy.impl .PhoneWindow.setContentView (PhoneWindow.java:281) на android.app.Activity.setContentView (Activity.java:1881) на com.example. prateekchachra.projectconnecttoastmasters.MapScreen.onCreate (MapScreen.java:34) на android.app.Activity.performCreate (Activity.java:5122) на android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1081) на андроид. app.ActivityThread.performLaunchActivity (ActivityThread.java:2307) на android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2395) на android.app.ActivityThread.доступ $ 600 (ActivityThread.java:162) на android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1364) на android.os.Handler.dispatchMessage (Handler.java:107) на android.os.Looper .loop (Looper.java:194) at android.app.ActivityThread.main (ActivityThread.java:5371) at java.lang.reflect.Method.invokeNative (собственный метод) по адресу java.lang.reflect.Method. invoke (Method.java:525) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:833) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:60 0) at dalvik.system.NativeStart.main (родной метод) Вызвано: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment не может быть добавлено в android.app.Fragment на android.app .Fragment.instantiate (Fragment.java:585) на android.app.Fragment.instantiate (Fragment.java:560) на android.app.Activity.onCreateView (Activity.java:4727) на android.view.LayoutInflater .createViewFromTag (LayoutInflater.java:680) на android.view.LayoutInflater.rInflate (LayoutInflater.java:746) на android.view.LayoutInflater.inflate (макет Inflater.java:489) на android.view.LayoutInflater.inflate (LayoutInflater.java:396) на android.view.LayoutInflater.inflate (LayoutInflater.java:352) на com.android.internal.policy.impl. PhoneWindow.setContentView (PhoneWindow.java:281) на android.app.Activity.setContentView (Activity.java:1881) на com.example.prateekchachra.projectconnecttoastmasters.MapScreen.onCreate (MapScreen.java:34) на android. app.Activity.performCreate (Activity.java:5122) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1081) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2307) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2395) at android.app.ActivityThread.access $ 600 (ActivityThread.java:162) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1364) на android.os.Handler.dispatchMessage (Handler.java:107) на android.os.Looper.loop (Looper.java:194) at android.app.ActivityThread.main (ActivityThread.java:5371) по адресу java.lang.reflect.Method.invokeNative (собственный метод) в java. lang.reflect.Method.invoke (Method.java:525) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:833) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:600) на dalvik.system.NativeStart.main (Native Method)
Можете ли вы показать нам журнал трассировки, когда приложение сбой и Manifest также –
Его закрытый ключ, у меня есть Это не проблема здесь, я отлаживаю ее прямо сейчас и вставляю трассировку журнала ASAP. –