2016-11-20 4 views
9

위도와 경도의 경로를 그려야합니다. 여기 내 MapsActivity.java가 있습니다.왜 Google지도에서이 오류가 발생합니까? DynamiteLoader를로드하지 못했습니다. java.lang.ClassNotFoundException : 클래스를 찾지 못했습니다.

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) 
getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 

     find = (Button) findViewById(R.id.btnFindPath); 
     or = (EditText) findViewById(R.id.etOrigin); 
     dest = (EditText) findViewById(R.id.etDestination); 


     find.setOnClickListener(new View.OnClickListener() { 
      @Override 

      public void onClick(View view) { 

      sendRequest(); 

      } 
     }); 
    } 

    public void sendRequest(){ 

     String origin = or.getText().toString(); 
     String destination = dest.getText().toString(); 

     if(origin.isEmpty()){ 
      Toast.makeText(this,"Please Enter the Origin" , Toast.LENGTH_SHORT).show(); 
     } 

     if(destination.isEmpty()){ 
      Toast.makeText(this,"Please Enter the Destination" , Toast.LENGTH_SHORT).show(); 
     } 

     DirectionFinder directionFinder = new DirectionFinder(origin, destination); 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     /*double array [] = {44.968046 ,-94.420307 ,44.33328,-89.132008, 33.755787,-116.359998,33.844843,-116.54911 ,44.92057 ,-93.44786}; 
     // Add a marker in Sydney and move the camera 
     for (int i = 0 ; i< array.length ; i = i+2){ 

      LatLng place = new LatLng(array[i], array[i+1]); 
      mMap.addMarker(new MarkerOptions().position(place).title("Marker in"+ i)); 
      mMap.moveCamera(CameraUpdateFactory.newLatLng(place)); 

     } 

    } 
} 

내 DirectionFinder.java은 다음과 같습니다

 public DirectionFinder(String or , String dest) { 



     if(or.equals("PRAN RFL")){ 
      double lat1 = 23.781388 ; 
      double lon1 = 90.425500 ; 
      LatLng origin = new LatLng(lat1, lon1); 
     } 

     if(dest.equals("Gulshan")){ 

      double lat2 = 23.780270 ; 
      double lon2 = 23.780270 ; 
      LatLng destination = new LatLng(lat2, lon2); 

     } 

     //this.listener = listener; 
     // this.origin = origin; 
     // this.destination = destination; 
    } 

    public void execute() throws UnsupportedEncodingException { 
     listener.onDirectionFinderStart(); 
     new DownloadRawData().execute(createUrl()); 
    } 

    private String createUrl() throws UnsupportedEncodingException { 
     String urlOrigin = URLEncoder.encode(origin, "utf-8"); 
     String urlDestination = URLEncoder.encode(destination, "utf-8"); 

     return DIRECTION_URL_API + "origin=" + urlOrigin + "&destination=" + urlDestination + "&key=" + GOOGLE_API_KEY; 
    } 

    private class DownloadRawData extends AsyncTask<String, Void, String> { 

     @Override 
     protected String doInBackground(String... params) { 
      String link = params[0]; 
      try { 
       URL url = new URL(link); 
       InputStream is = url.openConnection().getInputStream(); 
       StringBuffer buffer = new StringBuffer(); 
       BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 

       String line; 
       while ((line = reader.readLine()) != null) { 
        buffer.append(line + "\n"); 
       } 

       return buffer.toString(); 

      } catch (MalformedURLException e) { 
       e.printStackTrace(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(String res) { 
      try { 
       parseJSon(res); 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    private void parseJSon(String data) throws JSONException { 
     if (data == null) 
      return; 

     List<Route> routes = new ArrayList<Route>(); 
     JSONObject jsonData = new JSONObject(data); 
     JSONArray jsonRoutes = jsonData.getJSONArray("routes"); 
     for (int i = 0; i < jsonRoutes.length(); i++) { 
      JSONObject jsonRoute = jsonRoutes.getJSONObject(i); 
      Route route = new Route(); 

      JSONObject overview_polylineJson = jsonRoute.getJSONObject("overview_polyline"); 
      JSONArray jsonLegs = jsonRoute.getJSONArray("legs"); 
      JSONObject jsonLeg = jsonLegs.getJSONObject(0); 
      JSONObject jsonDistance = jsonLeg.getJSONObject("distance"); 
      JSONObject jsonDuration = jsonLeg.getJSONObject("duration"); 
      JSONObject jsonEndLocation = jsonLeg.getJSONObject("end_location"); 
      JSONObject jsonStartLocation = jsonLeg.getJSONObject("start_location"); 

      route.distance = new Distance(jsonDistance.getString("text"), jsonDistance.getInt("value")); 
      route.duration = new Duration(jsonDuration.getString("text"), jsonDuration.getInt("value")); 
      route.endAddress = jsonLeg.getString("end_address"); 
      route.startAddress = jsonLeg.getString("start_address"); 
      route.startLocation = new LatLng(jsonStartLocation.getDouble("lat"), jsonStartLocation.getDouble("lng")); 
      route.endLocation = new LatLng(jsonEndLocation.getDouble("lat"), jsonEndLocation.getDouble("lng")); 
      route.points = decodePolyLine(overview_polylineJson.getString("points")); 

      routes.add(route); 
     } 

     listener.onDirectionFinderSuccess(routes); 
    } 

    private List<LatLng> decodePolyLine(final String poly) { 
     int len = poly.length(); 
     int index = 0; 
     List<LatLng> decoded = new ArrayList<LatLng>(); 
     int lat = 0; 
     int lng = 0; 

     while (index < len) { 
      int b; 
      int shift = 0; 
      int result = 0; 
      do { 
       b = poly.charAt(index++) - 63; 
       result |= (b & 0x1f) << shift; 
       shift += 5; 
      } while (b >= 0x20); 
      int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
      lat += dlat; 

      shift = 0; 
      result = 0; 
      do { 
       b = poly.charAt(index++) - 63; 
       result |= (b & 0x1f) << shift; 
       shift += 5; 
      } while (b >= 0x20); 
      int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
      lng += dlng; 

      decoded.add(new LatLng(
        lat/100000d, lng/100000d 
      )); 
     } 

     return decoded; 
    } 
} 

내 활동 레이아웃은 다음과 같습니다

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:context="com.pran.trackingapp.MapsActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/etOrigin" 
     android:hint="Enter origin address" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="Enter destination address" 
     android:id="@+id/etDestination" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Find path" 
      android:id="@+id/btnFindPath" /> 
     <ImageView 
      android:layout_marginLeft="20dp" 
      android:layout_marginTop="5dp" 
      android:layout_width="40dp" 
      android:layout_height="40dp" /> 
     <TextView 
      android:layout_marginLeft="5dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="0 km" 
      android:id="@+id/tvDistance" /> 

     <ImageView 
      android:layout_marginLeft="20dp" 
      android:layout_marginTop="5dp" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:padding="5dp" /> 
     <TextView 
      android:layout_marginLeft="5dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="0 min" 
      android:id="@+id/tvDuration" /> 
    </LinearLayout> 


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

</LinearLayout> 

하지만 오류를 생성 findpath 버튼을 클릭 한 후 : **

E/DynamiteModule: Failed to load DynamiteLoader: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.dynamite.DynamiteModule$DynamiteLoaderClassLoader" on path: DexPathList[[zip file "/data/app/com.pran.trackingapp-2/base.apk"],nativeLibraryDirectories

** 내 build.gradle (모듈)입니다 :

apply plugin: 'com.android.application' 

    android { 
     compileSdkVersion 25 
     buildToolsVersion "25.0.0" 

     defaultConfig { 
      applicationId "com.pran.trackingapp" 
      minSdkVersion 16 
      targetSdkVersion 25 
      versionCode 1 
      versionName "1.0" 
     } 
     buildTypes { 
      release { 
       minifyEnabled false 
       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
      } 
     } 
    } 

    dependencies { 
     compile fileTree(dir: 'libs', include: ['*.jar']) 
     testCompile 'junit:junit:4.12' 
     compile 'com.android.support:appcompat-v7:25.0.0' 
     compile 'com.google.android.gms:play-services:9.8.0' 
    } 

내 build.gradle (프로젝트)입니다 :

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.0.0' 
     classpath 'com.google.gms:google-services:3.0.0' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

경로가 그려지지 않았습니다. 지금 할 수 있습니까?

+0

모듈 레벨'build.gradle'을 여기에 추가 할 수 있습니까? – AndiGeeky

+0

네, –

+0

을 추가했습니다. 적용 플러그인을 잊어 버린 것 같아요 : –

답변

2

앱의 그라디언트 파일을 다음과 같이 변경하십시오.

이 하나가 build.gradle입니다 (프로젝트 : // 프로젝트 이름)

이 dependenies

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.2' 
     classpath 'com.google.gms:google-services:3.0.0' 
     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

classpath 'com.google.gms:google-services:3.0.0'를 추가하고이 일이 당신의 build.gradle에 대한 것입니다 (단위 : 응용 프로그램) 다른 서비스를 사용하지 않는 경우 은지도 단지 파일의 상단이나 하단에 추가 기대 구글에서이 줄을 추가하지 마십시오 apply plugin: 'com.google.gms.google-services'

도움이되기를 바랍니다.

+0

바뀐 내용 : ( –

+0

붙여 넣기 두 파일 모두 –

+0

완료했습니다. 두 파일을 모두 추가했습니다. –