2014-01-20 80 views
0

我有一個應用程序,當我點擊圖像時打開地圖。我對活動的佈局做了一些更改,地圖停止工作。我不知道錯誤是什麼,我沒有改變地圖類,清單也沒關係。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)); 
     } 

    } 
+0

顯示我們身邊的onCreate'it.stepapp.bajabeach.Dove_Siamo.onCreate(代碼Dove_Siamo.java:77)' –

+0

檢查編輯過的問題:) –

回答

0

通過這條線來看:

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" />

我驗證,如果谷歌Play服務庫項目是我的Java構建路徑上,因爲它在我看來,無法找到具有適當值的R類。

+0

google_play_services是在java build path-> projects下,應該沒問題 –

1

在我的清單文件中添加這兩行後就可以工作了。

爲Eclipse補充一點:

<meta-data android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version" /> 

<meta-data android:name="com.google.android.maps.v2.API_KEY" 
      android:value="Your KEY" /> 

如果您使用的是Android工作室(最新版本)與gradle0.7 +再加入這一行:

<meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="Your Key" /> 
+0

我已經試過這個,但錯誤仍然在這裏.... –

+0

檢查我編輯的答案..它應該幫助你。兩天後,我面臨同樣的問題。 –

+0

確保您生成的Sha1密鑰與確切的軟件包名稱匹配。 –

0

解決了! 檢查以下是否到位。

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="YOUR PACKAGE" 
    > 
<permission 
     android:name="YOUR PACKAGE.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

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

    <uses-permission android:name=" YOUR PACKAGE.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <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_NETWORK_STATE"/> 

<application 
…. 
> 


     <meta-data android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version" /> 
     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="YOUR API KEY " /> 
    </application> 
<!--In layout declaring.--> 

<fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.SupportMapFragment"/> 

import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 

public class MainActivity extends FragmentActivity { 
    private GoogleMap map; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); 
    } 
} 

這應該工作:) 編碼快樂谷歌地圖:)

+0

不... ...仍然崩潰... –

+0

它爲我工作。他們可能還有其他一些問題。請點擊此鏈接http://android-er.blogspot.in/2012/12/a-simple-example-using-google-maps.html – Vinayak