2012-09-14 75 views
0

你好再次感謝的答案,但是這不是我想要什麼切換+進入位置設置

這是錯誤,當我點擊按鈕看起來

09-15 06:25:41.936:D /錯誤點擊(442):這裏是onclick方法中的錯誤 09-15 06:25:41.936:點擊時發生D /錯誤(442):這裏是if語句中的錯誤 09-15 06:25:41.947:D/AndroidRuntime(442):關閉VM 09-15 06:25:41.947:W/dalvikvm(442):threadid = 1:線程退出時未捕獲的異常(group = 0x4001d800 ) 09-15 06:25:41。 957:E/AndroidRuntime(442):致命例外:主 09-15 06:25:41.957:​​E/AndroidRuntime(442):java.lang.NullPointerException 09-15 06:25:41.957:​​E/AndroidRuntime(442) ):com.androidhive.googlemaps.ShowMap.onClick(ShowMap.java:42) 09-15 06:25:41.957:​​E/AndroidRuntime(442):at android.view.View.performClick(View.java:2408) ) 09-15 06:25:41.957:​​E/AndroidRuntime(442):at android.view.View $ PerformClick.run(View.java:8816) 09-15 06:25:41.957:​​E/AndroidRuntime(442) ):at android.os.Handler.handleCallback(Handler.java:587) 09-15 06:25:41.957:​​E/AndroidRuntime(442):at android.os.Handler.dispatchMessage(Handler.java:92) 09-15 06:25:41.957:​​E/AndroidRuntime(442):at android.os.Looper.loop(Looper.java:123) 09-15 06:25:41.957:​​E/AndroidRuntime(442)在android.app.ActivityThread.main(ActivityThread.java:4627) 09-15 06:25:41.957:​​E/AndroidRuntime(442):at java.lang.reflect.Method.invokeNative(Native Method) 09-15 06:25:41.957:​​E/AndroidRuntime(442):在java.lang.reflect.Method.invoke(Method.java:521) 09-15 06:25:41.957:​​E/AndroidRuntime(442):at com。 android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 09-15 06:25:41.957:​​E/AndroidRuntime(442):at com.android.internal.os.ZygoteInit.main(ZygoteInit。 java:626) 09-15 06:25:41.957:​​E/AndroidRuntime(442):at dalvik.system.NativeStart.main(Native Method) 09-15 06:25:45.266:I/Process(442)發送信號。 PID:442 SIG:9

,這是該按鈕的代碼單擊

public void onClick(View v) { 

    gps = new NetworkSettings(); 

    Log.d("error on click ", "here is the error in the onclick method "); 

    if(isGPSEnabled) 
    { 
    // Log.d("error on click ", "here is the error in the if statement "); 

     Intent intent = new Intent(this, AndroidGoogleMapsActivity.class); 
     mContext.startActivity(intent); 
    } 

    Log.d("error on click ", "here is the error out the if statement "); 



     gps.showSettingsAlert(); 

} 

這就是showSettingsAlert()方法

公共無效showSettingsAlert(){ alertDialog =新AlertDialog。助洗劑(mContext);

Log.d("error on click ", "here is the error inthe top of the method "); 

    // Setting Dialog Title 
    alertDialog.setTitle("GPS is settings"); 

    // Setting Dialog Message 
    alertDialog 
      .setMessage("GPS is not enabled. Do you want to go to settings menu?"); 





    // On pressing Settings button 
    alertDialog.setPositiveButton("Settings", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        Intent intent = new Intent(
          Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
        mContext.startActivity(intent); 

       } 
      }); 


    // on pressing cancel button 
    alertDialog.setNegativeButton("Cancel", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 
       } 
      }); 


    // Showing Alert Message 
    alertDialog.show(); 
} 

我知道錯誤是在點擊按鈕,但我不知道它是什麼,如何解決它,請幫我

回答

0

尋找它......它可以給你任何想法...

 public Location getLocation() { 
    //android.os.Debug.waitForDebugger(); 
    try { 
     locationManager = (LocationManager) mContext 
       .getSystemService(LOCATION_SERVICE); 

     // getting GPS status 
     isGPSEnabled = locationManager 
       .isProviderEnabled(LocationManager.GPS_PROVIDER); 

     // getting network status 
     isNetworkEnabled = locationManager 
       .isProviderEnabled(LocationManager.NETWORK_PROVIDER); 

     if (isNetworkEnabled) { 
      this.canGetLocation = true; 
      locationManager.requestLocationUpdates(
        LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 
      Log.d("Network", "Network"); 
      if (locationManager != null) { 
       location = locationManager 
         .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
       if (location != null) { 
      //  locationManager.removeUpdates(GPSTracker.this); 
        latitude = location.getLatitude(); 
        longitude = location.getLongitude(); 

       } 
     // } 
     } 

     } 
     else if (isGPSEnabled){ 
      // if GPS Enabled get lat/long using GPS Services 
      this.canGetLocation = true; 
       locationManager.requestLocationUpdates(
         LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 
       Log.d("GPS Enabled", "GPS Enabled"); 
       if (locationManager != null) { 
        location = locationManager 
          .getLastKnownLocation(LocationManager.GPS_PROVIDER); 
        if (location != null) { 
        // locationManager.removeUpdates(GPSTracker.this); 
         latitude = location.getLatitude(); 
         longitude = location.getLongitude(); 

       } 
      } 
     } 
     else{ 
      //return location; 
      this.canGetLocation = false; 
     } 


    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    return location; 
} 
+0

謝謝你的答案,但那不是我想要的,所以我編輯我的問題,通過添加一些錯誤代碼似乎更容易理解 – jiji

0
Intent intent = new Intent(); 
intent.setClass(AndroidGPSTrackingActivity.this, mapslayout.class); 
startActivity(intent); 

清單:

<uses-library 
android:name="com.google.android.maps" 
android:required="true" /> 

像這樣使用,錯誤將被解決。