2017-04-19 7 views
-3

위도와 경도는 서버 에서뿐만 아니라 내 장치에서도 얻을 수 있습니다. 그것도 표시됩니다. 하지만 거리를 계산하려고하면 앱이 다운됩니다. 거리를 계산할 때 앱이 다운 됨

이는 로그 캣에서 내 로그 캣

04-19 15:27:27.717 28686-28686/? D/dalvikvm: Late-enabling CheckJNI 
04-19 15:27:27.785 28686-28686/com.example.john.bustrackclient I/InstantRun: Instant Run Runtime started. Android package is com.example.john.bustrackclient, real application class is null. 
04-19 15:27:27.785 28686-28686/com.example.john.bustrackclient W/InstantRun: No instant run dex files added to classpath 
04-19 15:27:27.789 28686-28686/com.example.john.bustrackclient I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts 
04-19 15:27:27.789 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve interface method 16119: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V 
04-19 15:27:27.789 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 
04-19 15:27:27.789 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;) 
04-19 15:27:27.789 28686-28686/com.example.john.bustrackclient I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested 
04-19 15:27:27.789 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve interface method 16121: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z 
04-19 15:27:27.789 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 
04-19 15:27:27.793 28686-28686/com.example.john.bustrackclient I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode 
04-19 15:27:27.793 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve interface method 16125: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; 
04-19 15:27:27.793 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 
04-19 15:27:27.793 28686-28686/com.example.john.bustrackclient I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations 
04-19 15:27:27.793 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve virtual method 697: Landroid/content/res/TypedArray;.getChangingConfigurations()I 
04-19 15:27:27.793 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 
04-19 15:27:27.797 28686-28686/com.example.john.bustrackclient I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType 
04-19 15:27:27.797 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve virtual method 719: Landroid/content/res/TypedArray;.getType (I)I 
04-19 15:27:27.797 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008 
04-19 15:27:27.833 28686-28686/com.example.john.bustrackclient I/dalvikvm: Could not find method android.widget.FrameLayout.startActionModeForChild, referenced from method android.support.v7.widget.ActionBarContainer.startActionModeForChild 
04-19 15:27:27.833 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve virtual method 16553: Landroid/widget/FrameLayout;.startActionModeForChild (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; 
04-19 15:27:27.837 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002 
04-19 15:27:27.881 28686-28686/com.example.john.bustrackclient I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList 
04-19 15:27:27.881 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve virtual method 430: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList; 
04-19 15:27:27.881 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006 
04-19 15:27:27.881 28686-28686/com.example.john.bustrackclient I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable 
04-19 15:27:27.889 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve virtual method 660: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 
04-19 15:27:27.889 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 
04-19 15:27:27.889 28686-28686/com.example.john.bustrackclient I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity 
04-19 15:27:27.889 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve virtual method 662: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 
04-19 15:27:27.889 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 
04-19 15:27:27.909 28686-28686/com.example.john.bustrackclient E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering 
04-19 15:27:27.909 28686-28686/com.example.john.bustrackclient W/dalvikvm: VFY: unable to resolve instanceof 157 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper; 
04-19 15:27:27.909 28686-28686/com.example.john.bustrackclient D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c 
04-19 15:27:28.093 28686-28686/com.example.john.bustrackclient D/libEGL: loaded /system/lib/egl/libEGL_genymotion.so 

                     [ 04-19 15:27:28.105 28686:28686 D/   ] 
                     HostConnection::get() New Host Connection established 0xb85a4440, tid 28686 
04-19 15:27:28.125 28686-28686/com.example.john.bustrackclient D/libEGL: loaded /system/lib/egl/libGLESv1_CM_genymotion.so 
04-19 15:27:28.129 28686-28686/com.example.john.bustrackclient D/libEGL: loaded /system/lib/egl/libGLESv2_genymotion.so 
04-19 15:27:28.237 28686-28686/com.example.john.bustrackclient W/EGL_genymotion: eglSurfaceAttrib not implemented 
04-19 15:27:28.325 28686-28686/com.example.john.bustrackclient E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from GradienCache 
04-19 15:27:28.381 28686-28686/com.example.john.bustrackclient E/OpenGLRenderer: MAX_TEXTURE_SIZE: 8192 
04-19 15:27:28.413 28686-28686/com.example.john.bustrackclient E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from Caches::initConstraints() 
04-19 15:27:28.421 28686-28686/com.example.john.bustrackclient E/OpenGLRenderer: MAX_TEXTURE_SIZE: 8192 
04-19 15:27:28.421 28686-28686/com.example.john.bustrackclient D/OpenGLRenderer: Enabling debug mode 0 
04-19 15:27:28.465 28686-28686/com.example.john.bustrackclient D/dalvikvm: GC_FOR_ALLOC freed 262K, 10% free 3093K/3412K, paused 7ms, total 9ms 
04-19 15:27:35.709 28686-28686/com.example.john.bustrackclient D/dalvikvm: GC_FOR_ALLOC freed 77K, 8% free 3317K/3592K, paused 3ms, total 3ms 
04-19 15:27:35.709 28686-28686/com.example.john.bustrackclient I/dalvikvm-heap: Grow heap (frag case) to 4.369MB for 1127532-byte allocation 
04-19 15:27:35.713 28686-28695/com.example.john.bustrackclient D/dalvikvm: GC_FOR_ALLOC freed 1K, 6% free 4417K/4696K, paused 4ms, total 4ms 
04-19 15:27:35.737 28686-28686/com.example.john.bustrackclient D/AndroidRuntime: Shutting down VM 
04-19 15:27:35.737 28686-28686/com.example.john.bustrackclient W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4cebb20) 
04-19 15:27:35.741 28686-28686/com.example.john.bustrackclient E/AndroidRuntime: FATAL EXCEPTION: main 
                       Process: com.example.john.bustrackclient, PID: 28686 
                       java.lang.NullPointerException 
                        at java.lang.StringToReal.parseDouble(StringToReal.java:244) 
                        at java.lang.Double.parseDouble(Double.java:295) 
                        at com.example.john.bustrackclient.MainActivity.onClick(MainActivity.java:151) 
                        at android.view.View.performClick(View.java:4438) 
                        at android.view.View$PerformClick.run(View.java:18422) 
                        at android.os.Handler.handleCallback(Handler.java:733) 
                        at android.os.Handler.dispatchMessage(Handler.java:95) 
                        at android.os.Looper.loop(Looper.java:136) 
                        at android.app.ActivityThread.main(ActivityThread.java:5001) 
                        at java.lang.reflect.Method.invokeNative(Native Method) 
                        at java.lang.reflect.Method.invoke(Method.java:515) 
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                        at dalvik.system.NativeStart.main(Native Method) 
04-19 15:27:35.925 28686-28822/com.example.john.bustrackclient D/dalvikvm: GC_FOR_ALLOC freed 292K, 8% free 4644K/4996K, paused 11ms, total 11ms 
04-19 15:27:38.701 28686-28686/com.example.john.bustrackclient I/Process: Sending signal. PID: 28686 SIG: 9 

내 MainActivity.java

import android.Manifest; 
import android.app.ProgressDialog; 
import android.content.Context; 
import android.content.Intent; 
import android.content.pm.PackageManager; 
import android.location.Criteria; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.os.Parcelable; 
import android.support.v4.app.ActivityCompat; 
import android.support.v7.app.AlertDialog; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 

import com.android.volley.RequestQueue; 
import com.android.volley.Response; 
import com.android.volley.VolleyError; 
import com.android.volley.toolbox.StringRequest; 
import com.android.volley.toolbox.Volley; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import static com.android.volley.Request.Method.GET; 
import static com.example.john.bustrackclient.R.id.textView4; 

public class MainActivity extends AppCompatActivity implements View.OnClickListener,LocationListener { 

    LocationManager locationManager; 
    String mprovider; 
    String latitude, longitude,latitude1,longitude1; 

    private EditText editTextId; 
    private Button buttonGet; 
    private TextView textViewResult,textView6; 

    private ProgressDialog loading; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     editTextId = (EditText) findViewById(R.id.editTextId); 
     buttonGet = (Button) findViewById(R.id.buttonGet); 
     textViewResult = (TextView) findViewById(R.id.textViewResult); 

     buttonGet.setOnClickListener(this); 

     locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     Criteria criteria = new Criteria(); 

     mprovider = locationManager.getBestProvider(criteria, false); 

     if (mprovider != null && !mprovider.equals("")) { 
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
       return; 
      } 
      Location location = locationManager.getLastKnownLocation(mprovider); 
      locationManager.requestLocationUpdates(mprovider, 15000, 1, this); 

      if (location != null) 
       onLocationChanged(location); 
      else 
       Toast.makeText(getBaseContext(), "No Location Provider Found Check Your Code", Toast.LENGTH_SHORT).show(); 
     } 
    } 

    public void onLocationChanged(Location location) { 
     TextView latitude = (TextView) findViewById(R.id.textView2); 
     TextView longitude = (TextView) findViewById(R.id.textView3); 

     latitude.setText("Latitude: " + location.getLatitude()); 
     longitude.setText("Longitude: " + location.getLongitude()); 

    } 

    public void onStatusChanged(String s, int i, Bundle bundle) { 
    } 

    public void onProviderEnabled(String s) { 
    } 

    public void onProviderDisabled(String s) { 
    } 


    private void getData() { 
     String destination = editTextId.getText().toString().trim(); 
     if (destination.equals("")) { 
      Toast.makeText(this, "Please enter your destination", Toast.LENGTH_LONG).show(); 
      return; 
     } 
     loading = ProgressDialog.show(this, "Please wait...", "Fetching...", false, false); 

     String url = Config.DATA_URL + editTextId.getText().toString().trim(); 

     StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() { 
      @Override 
      public void onResponse(String response) { 
       loading.dismiss(); 
       showJSON(response); 
      } 
     }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError error) { 
         Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_LONG).show(); 
        } 
       }); 

     RequestQueue requestQueue = Volley.newRequestQueue(this); 
     requestQueue.add(stringRequest); 
    } 

    private void showJSON(String response){ 
     latitude1=""; 
     longitude1=""; 
     try { 
      JSONObject jsonObject = new JSONObject(response); 
      JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY); 
      JSONObject updata = result.getJSONObject(0); 
      latitude1 = updata.getString(Config.KEY_LATITUDE); 
      longitude1 = updata.getString(Config.KEY_LONGITUDE); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
     textViewResult.setText("Latitude: "+latitude1+"\nLongitude: "+longitude1); 
    } 



    @Override 
    public void onClick(View v) 
    { 

     getData(); 
     int MILLION = 1000000; 
     int EARTH_RADIUS_KM = 6371; 

     double lati1=Double.parseDouble(latitude); 
     double long1=Double.parseDouble(longitude); 
     double lati2=Double.parseDouble(latitude1); 
     double long2=Double.parseDouble(longitude1); 

     double lat1 = lati1/MILLION; 
     double lon1 = long1/MILLION; 
     double lat2 = lati2/MILLION; 
     double lon2 = long2/MILLION; 

     double lat1Rad = Math.toRadians(lat1); 
     double lat2Rad = Math.toRadians(lat2); 
     double deltaLonRad = Math.toRadians(lon2 - lon1); 

     double dist = Math 
       .acos(Math.sin(lat1Rad) * Math.sin(lat2Rad) + Math.cos(lat1Rad) 
         * Math.cos(lat2Rad) * Math.cos(deltaLonRad)) 
       * EARTH_RADIUS_KM; 

     String distance=Double.toString(dist); 
     textView6.setText(distance); 
    } 
} 

, 나는 그것을 변환 오류가 될 수 있다고 생각 ...하지만 난 확실하지 않다.

도움을 주시면 감사하겠습니다 !!! 여기에 반환되는 것을

+1

그래서 기본적으로 앱에서 NullPointerException을 발생시킵니다. 나는 이미 그 질문에 1-2 번 대답했을지 모른다. – markspace

+0

가능한 [NullPointerException은 무엇이며 어떻게 수정합니까?] (http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it)) – csmckelvey

+0

나는 151 호로 의심된다. ​​ – markspace

답변

0

확인 :

latitude1 = updata.getString(Config.KEY_LATITUDE); 
longitude1 = updata.getString(Config.KEY_LONGITUDE); 

이 JSON 응답처럼 보인다는 잘못된 데이터 또는 실제로는 것을 다른 무언가를 기대가 포함되어 있습니다. 이 경우에는 값이 Config.KEY_LATITUDE으로 정의 된 이름이있는 필드가없는 것으로 보입니다.

+0

인쇄 할 때 위도와 경도가 서버에 저장됩니다. 계산 부분을 추가 할 때만 응용 프로그램이 중단됩니다. – John

+0

디버거를 실행하고 131'latitude1 = updata.getString (Config.KEY_LATITUDE); 줄에 중단 점을 넣고'updata'에 저장 한 내용을 확인하고 예상 한 내용인지 확인하십시오. – snikolau