这是我得到的错误:
03-13 22:27:28.156: E/AndroidRuntime(1166): FATAL EXCEPTION: main
03-13 22:27:28.156: E/AndroidRuntime(1166): java.lang.RuntimeException: Unable to resume activity {com.androidpoiservice/com.androidpoiservice.ViewMapActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.os.Handler.dispatchMessage(Handler.java:99)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.os.Looper.loop(Looper.java:137)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-13 22:27:28.156: E/AndroidRuntime(1166): at java.lang.reflect.Method.invokeNative(Native Method)
03-13 22:27:28.156: E/AndroidRuntime(1166): at java.lang.reflect.Method.invoke(Method.java:511)
03-13 22:27:28.156: E/AndroidRuntime(1166): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-13 22:27:28.156: E/AndroidRuntime(1166): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-13 22:27:28.156: E/AndroidRuntime(1166): at dalvik.system.NativeStart.main(Native Method)
03-13 22:27:28.156: E/AndroidRuntime(1166): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-13 22:27:28.156: E/AndroidRuntime(1166): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.Activity.setContentView(Activity.java:1867)
03-13 22:27:28.156: E/AndroidRuntime(1166): at com.androidpoiservice.ViewMapActivity.onResume(ViewMapActivity.java:67)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.Activity.performResume(Activity.java:5082)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
03-13 22:27:28.156: E/AndroidRuntime(1166): ... 12 more
03-13 22:27:28.156: E/AndroidRuntime(1166): Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f050012, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.app.Activity.onCreateView(Activity.java:4669)
03-13 22:27:28.156: E/AndroidRuntime(1166): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-13 22:27:28.156: E/AndroidRuntime(1166): ... 22 more
这是代码:
public class ViewMapActivity extends Activity {
private static String TAG = "View Map";
private String username;
private String password;
private String name;
private String type;
private String SOAP_ACTION;
private String METHOD_NAME;
private String NAMESPACE;
private String URL;
private double latitude;
private double longitude;
private static LatLng Point = new LatLng(21 , 57);
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_map);
}
@Override
protected void onResume() {
super.onResume();
setContentView(R.layout.activity_view_map);
Log.e(TAG,"Here");
SOAP_ACTION = getString(R.string.server)+"POIWebServer/POIWebService/getMapData";
METHOD_NAME = "getMapData";
NAMESPACE = getString(R.string.server)+"POIWebServer/POIWebService";
URL = getString(R.string.server)+"POIWebServer/POIWebService/POIWebService?WSDL";
LoginInfo log = new LoginInfo();
username=log.username;
password=log.password;
getLocation();
Thread networkThread = new Thread(){
@Override
public void run(){
try {
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
String temp=username+"#"+password;
request.addProperty("unpass",temp);
temp=String.valueOf(latitude)+","+String.valueOf(longitude);
request.addProperty("pos",temp);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
final SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
final String responseStr = response.toString();
runOnUiThread (new Runnable(){
public void run(){
// try {
// if (googleMap == null) {
// googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
// }
// googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
String[] pois = responseStr.split("\\$");
for(int i=0;i<pois.length;i++){
String part=pois[i];
String[] poiData=part.split("#");
double poiX=Double.parseDouble(poiData[0]);
double poiY=Double.parseDouble(poiData[1]);
String type=poiData[2];
String name=poiData[3];
Log.e(TAG,part);
Point = new LatLng(poiX , poiY);
// Marker TP = googleMap.addMarker(new MarkerOptions().position(Point).title(name));
}
// } catch (Exception e) {
// e.printStackTrace();
// }
}
});
} catch(Exception e){
e.printStackTrace();
}
}
};
networkThread.start();
}
private void getLocation() {
// Get the location manager
LocationManager locationManager = (LocationManager)
getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(bestProvider);
LocationListener loc_listener = new LocationListener() {
public void onLocationChanged(Location l) {}
public void onProviderEnabled(String p) {}
public void onProviderDisabled(String p) {}
public void onStatusChanged(String p, int status, Bundle extras) {}
};
locationManager.requestLocationUpdates(bestProvider, 0, 0, loc_listener);
location = locationManager.getLastKnownLocation(bestProvider);
try {
latitude = location.getLatitude();
longitude = location.getLongitude();
} catch (NullPointerException e) {
latitude = -1.0;
longitude = -1.0;
}
}
}
这是layout.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:background="#0099cc"
tools:context="com.androidpoiservice.ViewMapActivity" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
我无法找出问题所在,请帮助我
答案 0 :(得分:2)
我认为您不应该在onResume()
中设置内容视图。从那里删除它。你反正已经在onCreate()
中做到了。这就是它所属的地方。