java-错误放大活动映射xml中的类片段
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-错误放大活动映射xml中的类片段,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含13537字,纯文字阅读大概需要20分钟。
内容图文
这个项目以前曾经工作过.运行该应用程序时,我不断收到InflateException.
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: Process: com.example.ali.googleandroid, PID: 14895
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ali.googleandroid/com.example.ali.googleandroid.MapsActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class fragment
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-01 12:16:36.102 14895-14895/com.example.ali.googleandroid E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class fragment
MapsActivity.java:
package com.example.ali.googleandroid;
import android.Manifest;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.media.MediaPlayer;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
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.UiSettings;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class MapsActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener, GoogleMap.OnMyLocationChangeListener, GoogleMap.OnMarkerClickListener {
private static final int REQUEST_FINE_LOCATION = 0;
private static int doubleTap =0;
static GoogleMap mMap;
MediaPlayer mp;
GoogleApiClient mGoogleApiClient;
LocationRequest mLocationRequest;
static Location myLocation;
static LocationManager lm;
LatLng latLng;
SupportMapFragment mFragment;
static ArrayList<Double> DataLon;
static ArrayList<Double> DataLatit;
static ArrayList<String> DataFirst_Name;
static ArrayList<String> DataSurname;
public static boolean closeDown = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mp = MediaPlayer.create(this, R.raw.two_tone_nav);
loadPermissions(Manifest.permission.ACCESS_FINE_LOCATION, REQUEST_FINE_LOCATION);
if (!isGooglePlayServicesAvailable()) {
finish();
}
setContentView(R.layout.activity_maps);
mFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMap = mFragment.getMap();
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setZoomGesturesEnabled(true);
buildGoogleApiClient();
mGoogleApiClient.connect();
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// public void requestPermissions(@NonNull String[] permissions, int requestCode)
// 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 Activity#requestPermissions for more details.
return;
}
myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (myLocation != null) {
double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(20));
mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(" You are here!"));
}
//insert gather data methods
GatherDataLocLogon();
GatherUserLogon();
//*************Add for loop to load all submitted diary entries******************
for (int i = 0; i < SignInScreen.DEntry.size(); i++) {
String Lat = SignInScreen.Latit.get(i);
double DoubleLat = Double.parseDouble(Lat);
String Long = SignInScreen.Lon.get(i);
double DoubleLong = Double.parseDouble(Long);
// mMap.setOnMarkerClickListener(this);
LatLng NewLatLng = new LatLng(DoubleLong, DoubleLat);
mMap.addMarker(new MarkerOptions()
.position(new LatLng(DoubleLong, DoubleLat))
.title(SignInScreen.ETitle.get(i).toString())
.snippet(SignInScreen.DEntry.get(i).toString())
);
mMap.moveCamera(CameraUpdateFactory.newLatLng(NewLatLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(8));
}
}
activity_maps.xml:
<AbsoluteLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#619ec9"
xmlns:android="http://schemas.android.com/apk/res/android">
<fragment android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="362dp"
android:layout_height="323dp" tools:context=".MapsActivity"
/>
<ImageButton
android:onClick="CreateDiaryEntry"
android:layout_width="84dp"
android:layout_height="84dp"
android:id="@+id/DiaryEntry"
android:adjustViewBounds="true"
android:padding="20dp"
android:scaleType="fitXY"
android:layout_alignTop="@+id/trackownlocation"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/trackownlocation"
android:src="@drawable/create_entry"
android:background="@drawable/button_state4"
android:layout_alignParentStart="false"
android:layout_x="267dp"
android:layout_y="330dp" />
<ImageButton
android:onClick="TrackOwnLocation"
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/trackownlocation"
android:src="@drawable/own_location"
android:adjustViewBounds="true"
android:padding="20dp"
android:scaleType="fitXY"
android:layout_below="@+id/map"
android:layout_alignParentStart="false"
android:background="@drawable/button_state2"
android:layout_x="9dp"
android:layout_y="429dp" />
<ImageButton
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/help"
android:adjustViewBounds="true"
android:padding="20dp"
android:scaleType="fitXY"
android:src="@drawable/help"
android:background="@drawable/button_state3"
android:layout_alignTop="@+id/trackownlocation"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:layout_x="139dp"
android:layout_y="431dp" />
<ImageButton
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/imageButton"
android:src="@mipmap/settings_icon"
android:adjustViewBounds="true"
android:padding="20dp"
android:scaleType="fitXY"
android:layout_below="@+id/map"
android:layout_alignParentStart="false"
android:background="@drawable/button_state5"
android:layout_x="8dp"
android:layout_y="333dp" />
<ImageButton
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/imageButton2"
android:src="@mipmap/search_icon"
android:adjustViewBounds="true"
android:padding="20dp"
android:scaleType="fitXY"
android:layout_below="@+id/map"
android:layout_alignParentStart="false"
android:background="@drawable/button_state6"
android:layout_x="138dp"
android:layout_y="333dp" />
</AbsoluteLayout>
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ali.googleandroid" >
<!--
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-sdk
android:minSdkVersion="10"
android:targetSdkVersion="23" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.ali.googleandroid.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.ali.googleandroid.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.location.GPS_ENABLED_CHANGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
<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="@string/google_maps_key" />
<activity android:name=".SignInScreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Entry_Dislplay" >
</activity>
<activity android:name=".Diary_Entry" >
</activity>
<activity android:name=".Recover_Code" >
</activity>
<activity android:name=".SecDialog" >
</activity>
<activity android:name=".Create_A_New_Acc" >
</activity>
<activity android:name=".ThirDialog" >
</activity>
<activity android:name=".Help_Guide" >
</activity>
<activity android:name=".PersDialog" >
</activity>
<activity android:name=".MapsActivity" >
</activity>
<activity android:name=".LogoutDialog" >
</activity>
</application>
</manifest>
的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.ali.googleandroid"
minSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.google.android.gms:play-services:8.4.0'
}
解决方法:
您应该使用fragment class =“ com.google.android.gms.maps.SupportMapFragment” …而不是android:name =“ com.google.android.gms.maps.SupportMapFragment”
内容总结
以上是互联网集市为您收集整理的java-错误放大活动映射xml中的类片段全部内容,希望文章能够帮你解决java-错误放大活动映射xml中的类片段所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。