2016-08-02 4 views
0

こんにちは私は現在学校のプロジェクトをやっていますが、私はバグがどこにあるのか分かりません。私のコードも間違っていると思いません。これは私のコードです これは私の全プロジェクトですガイド drive.google.com/open?id=0B0MY4kATEXqlMDQyZWprRDhmeUUこの次の行はID LIKE Sring返品CameraUpdateFactory.newLatLngZoomがnullを返します

private void sendRequest() { 
    String origin = etOrigin.getText().toString(); 
    String destination = etDestination.getText().toString(); 
    String[] destinationArray = {"v.mapa","Vasra","Culiat"}; 

    if (origin.isEmpty()) { 
     Toast.makeText(this, "Please enter origin address!", Toast.LENGTH_SHORT).show(); 
     return; 
    } 
    if (destination.isEmpty()) { 
     Toast.makeText(this, "Please enter destination address!", Toast.LENGTH_SHORT).show(); 
     return; 
    } 

     try { 
      new DirectionFinder(this, origin, destinationArray[2]).execute(); 
      } catch (UnsupportedEncodingException e) { 
      e.printStackTrace(); 
        } 
    try { 
     new DirectionFinder(this, destinationArray[2], destinationArray[1]).execute(); 
    } catch (UnsupportedEncodingException e) { 
     e.printStackTrace(); 
    } 

@Override 
public void onDirectionFinderSuccess(List<Route> routes) { 
    progressDialog.dismiss(); 
    progressDialog.dismiss(); 
    polylinePaths = new ArrayList<>(); 
    originMarkers = new ArrayList<>(); 
    destinationMarkers = new ArrayList<>(); 
for (Route route : routes) { 
    Toast.makeText(
      MainActivity.this, 
      route.startLocation.toString(), 
      Toast.LENGTH_LONG).show(); 

//、私はするCameraUpdateが

  googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(route.startLocation, 16)); 
    //((TextView) findViewById(R.id.textView2)).setText(route.duration.text); 
    //((TextView) findViewById(R.id.textView3)).setText(route.distance.text); 

    originMarkers.add(googleMap.addMarker(new MarkerOptions() 
      .icon(BitmapDescriptorFactory.fromResource(R.drawable.start_blue)) 
      .title(route.startAddress) 
      .position(route.startLocation))); 
    destinationMarkers.add(googleMap.addMarker(new MarkerOptions() 
      .icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green)) 
      .title(route.endAddress) 
      .position(route.endLocation))); 

    PolylineOptions polylineOptions = new PolylineOptions(). 
      geodesic(true). 
      color(Color.BLUE). 
      width(10); 

    for (int i = 0; i < route.points.size(); i++) 
     polylineOptions.add(route.points.get(i)); 

    polylinePaths.add(googleMap.addPolyline(polylineOptions)); 

    routes.clear(); 
} 
} 
をスローしようとしているデータ型のルートの種類を知っていれば知ってはいけません

それ以降

Process: com.hci_thesis.thesis_dolph, PID: 4479 
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.moveCamera(com.google.android.gms.maps.CameraUpdate)' on a null object reference 
at com.hci_thesis.thesis_dolph.MainActivity.onDirectionFinderSuccess(MainActivity.java:269) 
at mods.DirectionFinder.parseJSon(DirectionFinder.java:129) 
at mods.DirectionFinder.access$100(DirectionFinder.java:25) 
at mods.DirectionFinder$DownloadRawData.onPostExecute(DirectionFinder.java:87) 
at mods.DirectionFinder$DownloadRawData.onPostExecute(DirectionFinder.java:58) 
at android.os.AsyncTask.finish(AsyncTask.java:632) 
at android.os.AsyncTask.access$600(AsyncTask.java:177) 
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5221) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 

答えて

0

NullPointerExceptionこのエラーをGETオブジェクトが必要な場合に、アプリケーションはnullを使用しようとしたときにスローされます。これらは以下を含みます:

  • nullオブジェクトのインスタンスメソッドを呼び出します。
  • nullオブジェクトのフィールドへのアクセスまたは変更。
  • nullの長さを配列のように見ます。
  • ヌルのスロットを配列のようにアクセスまたは変更する。
  • Throwable値であるかのようにnullをスローします。

あなたの場合、コードのこの部分にエラーが発生しますCameraUpdateFactory.newLatLngZoom。この[ドキュメント](https://developers.google.com/android/reference/com/google/android/gms/maps/CameraUpdateFactory#newLatLngZoom(com.google.android.gms.maps.model.LatLng、float)をチェックすると、このメソッドの値を適切に設定する方法がわかります。

CameraUpdateFactoryの使用方法については、pageをご確認ください。

また、GoogleマップAndroid APIのpartをチェックして、このメソッドの使用方法のサンプルコードを確認してください。

+0

T_Tだが私のコードサー –

関連する問題