我有一個應用程序,當我點擊圖像時打開地圖。我對活動的佈局做了一些更改,地圖停止工作。我不知道錯誤是什麼,我沒有改變地圖類,清單也沒關係。android - 打開地圖使應用程序崩潰
這裏是我的setOnClickListner:
dove.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
conn=isOnline();
if (conn==true){
Toast.makeText(contatti.this,"Connessione dati PRESENTE...", Toast.LENGTH_SHORT)
.show();
final ProgressDialog pd = ProgressDialog.show(contatti.this, "", "Attendere...", true);
new Thread(new Runnable(){
public void run(){
Intent intent = new Intent(contatti.this, Dove_Siamo.class);
startActivity(intent);
pd.dismiss();
}
}).start();
} else {
new AlertDialog.Builder(contatti.this)
.setTitle("ATTENZIONE!!!")
.setMessage("Connessione dati assente. Non è possibile proseguire!!!")
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//do nothing
dialog.cancel();
}
})
.setIcon(R.drawable.ic_andro)
.show();
}
}
});
和logcat的:
01-20 20:02:29.548: E/AndroidRuntime(24562): FATAL EXCEPTION: main
01-20 20:02:29.548: E/AndroidRuntime(24562): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.stepapp.bajabeach/it.stepapp.bajabeach.Dove_Siamo}: android.view.InflateException: Binary XML file line #44: Error inflating class fragment
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2081)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2106)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.app.ActivityThread.access$700(ActivityThread.java:134)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1217)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.os.Looper.loop(Looper.java:137)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.app.ActivityThread.main(ActivityThread.java:4856)
01-20 20:02:29.548: E/AndroidRuntime(24562): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 20:02:29.548: E/AndroidRuntime(24562): at java.lang.reflect.Method.invoke(Method.java:511)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
01-20 20:02:29.548: E/AndroidRuntime(24562): at dalvik.system.NativeStart.main(Native Method)
01-20 20:02:29.548: E/AndroidRuntime(24562): Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class fragment
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:133)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:261)
01-20 20:02:29.548: E/AndroidRuntime(24562): at it.stepapp.bajabeach.Dove_Siamo.onCreate(Dove_Siamo.java:77)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.app.Activity.performCreate(Activity.java:5047)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)
01-20 20:02:29.548: E/AndroidRuntime(24562): ... 11 more
01-20 20:02:29.548: E/AndroidRuntime(24562): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4132500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.maps.internal.q.v(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.maps.internal.q.u(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.maps.SupportMapFragment$b.eb(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.dynamic.a.a(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:269)
01-20 20:02:29.548: E/AndroidRuntime(24562): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
01-20 20:02:29.548: E/AndroidRuntime(24562): ... 23 more
01-20 20:02:29.588: E/android.os.Debug(24370): [email protected] > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error
如何解決這個任何想法?
編輯:在OnCreate代碼:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dove_siamo);
//sherlock actionbar code
Drawable dab=getResources().getDrawable(R.drawable.frontespizio);
ActionBar ab;
ab = getSupportActionBar();
Drawable b=getResources().getDrawable(R.drawable.sfondoab);
ab.setSplitBackgroundDrawable(b);
if (ab.isShowing()) {
ab.setBackgroundDrawable(dab);
ab.setDisplayShowHomeEnabled(false);
ab.setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.abs_layout);
ImageButton info=(ImageButton) findViewById(R.id.bottone1);
info.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Dove_Siamo.this, Stepapp_info.class);
startActivity(intent);
}
});
}
current=null;
location=null;
test = (TextView) findViewById(R.id.tv_info);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provs=locationManager.getProviders(true);
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
mlat = (double) location.getLatitude();
mlng = (double) location.getLongitude();
KIEL = new LatLng(mlat, mlng);
}else {
mlat = (double) 53.551;
mlng = (double) 9.993;
KIEL = new LatLng(mlat, mlng);
}
geocoder = new Geocoder(Dove_Siamo.this);
mIndirizzi = geocoder.getFromLocationName(indirizzo, 1);
mappato = mIndirizzi.get(0);
lat = (double) (mappato.getLatitude());
lng = (double) (mappato.getLongitude());
HAMBURG = new LatLng(lat, lng);
locFound=1;
} catch (IOException e) {
lat = 41.857512;
lng = 12.502932;
HAMBURG = new LatLng(lat, lng);
e.printStackTrace();
}
//######## per sdk7
FragmentManager fragmentManager = getSupportFragmentManager();
SupportMapFragment mapFragment = (SupportMapFragment)
fragmentManager.findFragmentById(R.id.map);
map=mapFragment.getMap();
//#######
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null);
hamburg = map.addMarker(new MarkerOptions().position(HAMBURG).title(indirizzo));
kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Tu sei qui")
.snippet("enjoy")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_andro)));
String url = "http://maps.googleapis.com/maps/api/directions/json?origin="
+ mlat
+ ","
+ mlng
+ "&destination="
+ lat
+ "," + lng + "&sensor=false";
Log.i("Dove_Siamo",url);
JSONDrivingDirectionsParser parser = new JSONDrivingDirectionsParser(url);
punti = parser.getPath();
info = parser.getInfo();
test = (TextView) findViewById(R.id.tv_info);
test.setText(info);
String distanza="Sei a "+info;
test.setText(distanza);
for(int i = 0; i<punti.size()-1;i++){
GeoPoint src1 = punti.get(i);
GeoPoint dst1 = punti.get(i+1);
double lts = (double) (src1.getLatitudeE6())/1E5;
double lngs = (double) (src1.getLongitudeE6())/1E5;
LatLng src= new LatLng(lts,lngs);
double ltd = (double) (dst1.getLatitudeE6())/1E5;
double lngd = (double) (dst1.getLongitudeE6())/1E5;
LatLng dest= new LatLng(ltd,lngd);
Polyline line = map.addPolyline(new PolylineOptions()
.add(new LatLng(src.latitude, src.longitude), new LatLng(dest.latitude, dest.longitude))
.width(4)
.color(Color.BLUE).geodesic(true));
}
}
顯示我們身邊的onCreate'it.stepapp.bajabeach.Dove_Siamo.onCreate(代碼Dove_Siamo.java:77)' –
檢查編輯過的問題:) –