gpt4 book ai didi

android - Android 应用程序运行时异常 : unable to inflate MapFragment

转载 作者:行者123 更新时间:2023-11-29 16:00:09 28 4
gpt4 key购买 nike

我已经发布了一个与此类似的问题,我已经插入了向我建议的更改,但我不明白为什么要启动此异常.

list 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testing"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />

<permission
android:name="com.example.testing.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.example.testing.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.testing.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

主要 Activity 代码:

public class MainActivity extends Activity implements OnClickListener, GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener, LocationListener {

private static final long UPDATE_INTERVAL = 5000;
private static final long FASTEST_INTERVAL = 1000;

private Button showBtn;
private GoogleMap map = null;
private LocationClient locationClient;
private Location myLocation;
private LocationRequest locationRequest;
private Display display;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showBtn = (Button) findViewById(R.id.showBtn);
showBtn.setOnClickListener(this);
showBtn.setClickable(false);

map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);

display = new Display(map);

locationClient = new LocationClient(this, this, this);
locationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(UPDATE_INTERVAL)
.setFastestInterval(FASTEST_INTERVAL).setSmallestDisplacement(10);

if (locationClient != null)
locationClient.connect();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onLocationChanged(Location location) {
Toast.makeText(this, "Location listener called", Toast.LENGTH_SHORT).show();
LatLng newPosition = new LatLng(location.getLatitude(), location.getLongitude());

myLocation = location;
if (myLocation != null)
showBtn.setClickable(true);
else
showBtn.setClickable(false);

display.clearMap();
map.animateCamera(CameraUpdateFactory.newLatLngZoom(newPosition, 16));
display.addMarker(newPosition, "My Title", "..and my comments go here");
display.setCircleOnMap(newPosition);
}

@Override
public void onConnectionFailed(ConnectionResult arg0) {
}

@Override
public void onConnected(Bundle arg0) {
Toast.makeText(this, "Locationclient Connected", Toast.LENGTH_SHORT).show();
locationClient.requestLocationUpdates(locationRequest, this);
}

@Override
public void onDisconnected() {
Toast.makeText(this, "Disconnected. Please re-connect.", Toast.LENGTH_SHORT).show();
}

@Override
public void onClick(View v) {
if (v.getId() == R.id.showBtn) {
if (InternetStatus.getInstance(this).isOnline(this)) {
new ShowCloseUps(display, myLocation).execute();
} else
Toast.makeText(this, "No internet connection find one and retry!!", Toast.LENGTH_LONG).show();
}
}

@Override
protected void onDestroy() {
if (locationClient.isConnected() && locationClient != null) {
locationClient.removeLocationUpdates(this);
locationClient.disconnect();
}
super.onDestroy();
}
}

activity_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"
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=".MainActivity" >

<Button
android:id="@+id/showBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/show"
/>

<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/showBtn"
android:name="com.google.android.gms.maps.MapFragment"
map:cameraZoom="5"
map:cameraTilt="30"
map:uiCompass="false"
map:uiRotateGestures="true"
map:uiTiltGestures="true"
map:uiZoomGestures="true"
/>
</RelativeLayout>

我的 logcat 选项卡已更新:

    08-11 08:46:40.250: E/AndroidRuntime(1832): FATAL EXCEPTION: main
08-11 08:46:40.250: E/AndroidRuntime(1832): Process: com.example.testing, PID: 1832
08-11 08:46:40.250: E/AndroidRuntime(1832): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testing/com.example.testing.MainActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.ActivityThread.access$800(ActivityThread.java:135)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.os.Handler.dispatchMessage(Handler.java:102)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.os.Looper.loop(Looper.java:136)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.ActivityThread.main(ActivityThread.java:5017)
08-11 08:46:40.250: E/AndroidRuntime(1832): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 08:46:40.250: E/AndroidRuntime(1832): at java.lang.reflect.Method.invoke(Method.java:515)
08-11 08:46:40.250: E/AndroidRuntime(1832): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-11 08:46:40.250: E/AndroidRuntime(1832): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-11 08:46:40.250: E/AndroidRuntime(1832): at dalvik.system.NativeStart.main(Native Method)
08-11 08:46:40.250: E/AndroidRuntime(1832): Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-11 08:46:40.250: E/AndroidRuntime(1832): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.Activity.setContentView(Activity.java:1929)
08-11 08:46:40.250: E/AndroidRuntime(1832): at com.example.testing.MainActivity.onCreate(MainActivity.java:39)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.Activity.performCreate(Activity.java:5231)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
08-11 08:46:40.250: E/AndroidRuntime(1832): ... 11 more
08-11 08:46:40.250: E/AndroidRuntime(1832): Caused by: java.lang.IllegalArgumentException: Binary XML file line #25: Must specify unique android:id, android:tag, or have a parent with an id for null
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.app.Activity.onCreateView(Activity.java:4759)
08-11 08:46:40.250: E/AndroidRuntime(1832): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
08-11 08:46:40.250: E/AndroidRuntime(1832): ... 21 more

最佳答案

从 fragment 中删除这一行

 xmlns:map="http://schemas.android.com/apk/res-auto" 

来自 activity_main.xml 文件。

同时删除这个:

map:cameraZoom="5"
map:cameraTilt="30"
map:uiCompass="false"
map:uiRotateGestures="true"
map:uiTiltGestures="true"
map:uiZoomGestures="true"

关于android - Android 应用程序运行时异常 : unable to inflate MapFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25242477/

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