0

android map 지향적 인 예제 프로젝트로 작업하는 동안 오류가 발생했습니다. 내가이 프로그램을 실행할 때 어느 한 날이 문제를 해결하는 데 도움이 바랍니다 수있는이 프로그램의 오류를 찾을 수 없습니다 로그를 기릅니다에서 NoClassDefFoundError를 보여줍니다 ..NoClassDefFoundError가 android 프로젝트를 실행하는 동안 logcat에 표시됩니다.

PlacesMapActivity.java

public class MainActivity extends Activity { 

    // flag for Internet connection status 
    Boolean isInternetPresent = false; 

    // Connection detector class 
    ConnectionDetector cd; 

    // Alert Dialog Manager 
    AlertDialogManager alert = new AlertDialogManager(); 

    // Google Places 
    GooglePlaces googlePlaces; 

    // Places List 
    PlacesList nearPlaces; 

    // GPS Location 
    GPSTracker gps; 

    // Button 
    Button btnShowOnMap; 

    // Progress dialog 
    ProgressDialog pDialog; 

    // Places Listview 
    ListView lv; 

    // ListItems data 
    ArrayList<HashMap<String, String>> placesListItems = new ArrayList<HashMap<String,String>>(); 


    // KEY Strings 
    public static String KEY_REFERENCE = "reference"; // id of the place 
    public static String KEY_NAME = "name"; // name of the place 
    public static String KEY_VICINITY = "vicinity"; // Place area name 

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

     cd = new ConnectionDetector(getApplicationContext()); 

     // Check if Internet present 
     isInternetPresent = cd.isConnectingToInternet(); 
     if (!isInternetPresent) { 
      // Internet Connection is not present 
      alert.showAlertDialog(MainActivity.this, "Internet Connection Error", 
        "Please connect to working Internet connection", false); 
      // stop executing code by return 
      return; 
     } 

     // creating GPS Class object 
     gps = new GPSTracker(this); 

     // check if GPS location can get 
     if (gps.canGetLocation()) { 
      Log.d("Your Location", "latitude:" + gps.getLatitude() + ", longitude: " + gps.getLongitude()); 
     } else { 
      // Can't get user's current location 
      alert.showAlertDialog(MainActivity.this, "GPS Status", 
        "Couldn't get location information. Please enable GPS", 
        false); 
      // stop executing code by return 
      return; 
     } 

     // Getting listview 
     lv = (ListView) findViewById(R.id.list); 

     // button show on map 
     btnShowOnMap = (Button) findViewById(R.id.btn_show_map); 

     // calling background Async task to load Google Places 
     // After getting places from Google all the data is shown in listview 
     new LoadPlaces().execute(); 

     /** Button click event for shown on map */ 
     btnShowOnMap.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       Intent i = new Intent(getApplicationContext(), 
         PlacesMapActivity.class); 
       // Sending user current geo location 
       i.putExtra("user_latitude", Double.toString(gps.getLatitude())); 
       i.putExtra("user_longitude", Double.toString(gps.getLongitude())); 

       // passing near places to map activity 
       i.putExtra("near_places", nearPlaces); 
       // staring activity 
       startActivity(i); 
      } 
     }); 


     /** 
     * ListItem click event 
     * On selecting a listitem SinglePlaceActivity is launched 
     * */ 
     lv.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
        int position, long id) { 
       // getting values from selected ListItem 
       String reference = ((TextView) view.findViewById(R.id.reference)).getText().toString(); 

       // Starting new intent 
       Intent in = new Intent(getApplicationContext(), 
         SinglePlaceActivity.class); 

       // Sending place refrence id to single place activity 
       // place refrence id used to get "Place full details" 
       in.putExtra(KEY_REFERENCE, reference); 
       startActivity(in); 
      } 
     }); 
    } 

    /** 
    * Background Async Task to Load Google places 
    * */ 
    class LoadPlaces extends AsyncTask<String, String, String> { 

     /** 
     * Before starting background thread Show Progress Dialog 
     * */ 
     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      pDialog = new ProgressDialog(MainActivity.this); 
      pDialog.setMessage(Html.fromHtml("<b>Search</b><br/>Loading Places...")); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(false); 
      pDialog.show(); 
     } 

     /** 
     * getting Places JSON 
     * */ 
     protected String doInBackground(String... args) { 
      // creating Places class object 
      googlePlaces = new GooglePlaces(); 

      try { 
       // Separeate your place types by PIPE symbol "|" 
       // If you want all types places make it as null 
       // Check list of types supported by google 
       // 
       String types = "cafe|restaurant"; // Listing places only cafes, restaurants 

       // Radius in meters - increase this value if you don't find any places 
       double radius = 1000; // 1000 meters 

       // get nearest places 
       nearPlaces = googlePlaces.search(gps.getLatitude(), 
         gps.getLongitude(), radius, types); 


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

     /** 
     * After completing background task Dismiss the progress dialog 
     * and show the data in UI 
     * Always use runOnUiThread(new Runnable()) to update UI from background 
     * thread, otherwise you will get error 
     * **/ 
     protected void onPostExecute(String file_url) { 
      // dismiss the dialog after getting all products 
      pDialog.dismiss(); 
      // updating UI from Background Thread 
      runOnUiThread(new Runnable() { 
       public void run() { 
        /** 
        * Updating parsed Places into LISTVIEW 
        * */ 
        // Get json response status 
        String status = nearPlaces.status; 

        // Check for all possible status 
        if(status.equals("OK")){ 
         // Successfully got places details 
         if (nearPlaces.results != null) { 
          // loop through each place 
          for (Place p : nearPlaces.results) { 
           HashMap<String, String> map = new HashMap<String, String>(); 

           // Place reference won't display in listview - it will be hidden 
           // Place reference is used to get "place full details" 
           map.put(KEY_REFERENCE, p.reference); 

           // Place name 
           map.put(KEY_NAME, p.name); 


           // adding HashMap to ArrayList 
           placesListItems.add(map); 
          } 
          // list adapter 
          ListAdapter adapter = new SimpleAdapter(MainActivity.this, placesListItems, 
            R.layout.list_item, 
            new String[] { KEY_REFERENCE, KEY_NAME}, new int[] { 
              R.id.reference, R.id.name }); 

          // Adding data into listview 
          lv.setAdapter(adapter); 
         } 
        } 
        else if(status.equals("ZERO_RESULTS")){ 
         // Zero results found 
         alert.showAlertDialog(MainActivity.this, "Near Places", 
           "Sorry no places found. Try to change the types of places", 
           false); 
        } 
        else if(status.equals("UNKNOWN_ERROR")) 
        { 
         alert.showAlertDialog(MainActivity.this, "Places Error", 
           "Sorry unknown error occured.", 
           false); 
        } 
        else if(status.equals("OVER_QUERY_LIMIT")) 
        { 
         alert.showAlertDialog(MainActivity.this, "Places Error", 
           "Sorry query limit to google places is reached", 
           false); 
        } 
        else if(status.equals("REQUEST_DENIED")) 
        { 
         alert.showAlertDialog(MainActivity.this, "Places Error", 
           "Sorry error occured. Request is denied", 
           false); 
        } 
        else if(status.equals("INVALID_REQUEST")) 
        { 
         alert.showAlertDialog(MainActivity.this, "Places Error", 
           "Sorry error occured. Invalid Request", 
           false); 
        } 
        else 
        { 
         alert.showAlertDialog(MainActivity.this, "Places Error", 
           "Sorry error occured.", 
           false); 
        } 
       } 
      }); 

     } 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 



} 

는 MainActivity.java의 라인 (110)에 무엇

02-16 20:05:33.528: E/AndroidRuntime(367): FATAL EXCEPTION: main 
02-16 20:05:33.528: E/AndroidRuntime(367): java.lang.NoClassDefFoundError: com.androidhive.googleplacesandmaps.PlacesMapActivity 
02-16 20:05:33.528: E/AndroidRuntime(367): at com.androidhive.googleplacesandmaps.MainActivity$1.onClick(MainActivity.java:110) 
02-16 20:05:33.528: E/AndroidRuntime(367): at android.view.View.performClick(View.java:2408) 
02-16 20:05:33.528: E/AndroidRuntime(367): at android.view.View$PerformClick.run(View.java:8816) 
02-16 20:05:33.528: E/AndroidRuntime(367): at android.os.Handler.handleCallback(Handler.java:587) 
02-16 20:05:33.528: E/AndroidRuntime(367): at android.os.Handler.dispatchMessage(Handler.java:92) 
02-16 20:05:33.528: E/AndroidRuntime(367): at android.os.Looper.loop(Looper.java:123) 
02-16 20:05:33.528: E/AndroidRuntime(367): at android.app.ActivityThread.main(ActivityThread.java:4627) 
02-16 20:05:33.528: E/AndroidRuntime(367): at java.lang.reflect.Method.invokeNative(Native Method) 
02-16 20:05:33.528: E/AndroidRuntime(367): at java.lang.reflect.Method.invoke(Method.java:521) 
02-16 20:05:33.528: E/AndroidRuntime(367): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
02-16 20:05:33.528: E/AndroidRuntime(367): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
02-16 20:05:33.528: E/AndroidRuntime(367): at dalvik.system.NativeStart.main(Native Method) 
02-16 20:05:33.528: E/AndroidRuntime(367): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation 
02-16 20:05:33.528: E/AndroidRuntime(367): at dalvik.system.DexFile.defineClass(Native Method) 
02-16 20:05:33.528: E/AndroidRuntime(367): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:209) 
02-16 20:05:33.528: E/AndroidRuntime(367): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203) 
02-16 20:05:33.528: E/AndroidRuntime(367): at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 
02-16 20:05:33.528: E/AndroidRuntime(367): at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 
02-16 20:05:33.528: E/AndroidRuntime(367): ... 12 more 
+0

Intent에서 getApplicationContext() 대신 MainActivity.this를 사용하십시오. PlacesMapActivity를 등록 했습니까? –

+0

메인 활동을 시도했지만 PlacesMapActivity가 매니페스트에 있는지 확인했지만 오류가 sam –

+0

인 경우 target = Google Inc.:Google API : 8 대신 android = android-8 –

답변

1

Google API가 프로젝트> 속성> Android에서 선택되어 있는지 확인하십시오. 그렇지 않은 경우 적용을 클릭하십시오. 이 변경은 project.properties 파일의 대상 속성을 수정하고 포함 된 라이브러리를 변경합니다. (예 : 최신 안드로이드 SDK를 사용하면 다음과 같이됩니다 : target = Google Inc.:Google APIs : 14)

프로젝트> 속성> Java 빌드 경로> 라이브러리로 이동하여 android.jar 또는 maps가 없는지 확인하십시오. 항아리가 직접 포함되어 있습니다. 최소한 maps.jar 및 android.jar가있는 Google Apis 만 잎으로 사용해야합니다.

+0

Project> Properties> Java Build Path> 라이브러리에서 maps.jar 파일을 제거하면 매우 고마워요. –

0

를 로그 캣? 위의 코드를 선택적으로 붙여 넣었다는 것을 알면 불가능합니다. 위의 내용을 추측 할 수 있다면 사용자가 실행중인 기기보다 높은 API 레벨을 타겟팅한다고 말할 수 있습니다.

+0

과 같이 대상을 변경해야합니다. 라인 110은 의도 i = 새로운 인 텐트 (getApplicationContext(), PlacesMapActivity.class); –

관련 문제