Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行android项目时在logcat中显示NoClassDefFoundError_Android_Google Maps_Noclassdeffounderror_Google Places Api - Fatal编程技术网

运行android项目时在logcat中显示NoClassDefFoundError

运行android项目时在logcat中显示NoClassDefFoundError,android,google-maps,noclassdeffounderror,google-places-api,Android,Google Maps,Noclassdeffounderror,Google Places Api,我在使用android面向地图的示例项目时出错。当我运行这个程序时,它在log cat中显示了一个NoClassDefFoundError。我在这个程序中找不到任何错误。有人能帮我解决这个问题吗 PlacesMapActivity.java public class MainActivity extends Activity { // flag for Internet connection status Boolean isInternetPresent = false;

我在使用android面向地图的示例项目时出错。当我运行这个程序时,它在log cat中显示了一个NoClassDefFoundError。我在这个程序中找不到任何错误。有人能帮我解决这个问题吗

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行是什么?由于您选择性地粘贴了上面的代码,因此无法知道。如果我冒昧地猜测/戳穿上述内容,我会说您的目标API级别高于您运行它的设备。

确保在Project>Properties>Android中检查Google API。如果不是这种情况,选择它并单击应用。此更改将修改文件project.properties中的目标属性,并更改包含的库。(例如,使用最新的android sdk,您将拥有:target=Google Inc.:Google API:14)


转到项目>属性>Java构建路径>库,确保没有直接包含android.jar或maps.jar。您应该只使用至少带有maps.jar和android.jar作为叶子的Google API。

尝试MainActivity.this,而不是使用getApplicationContext(),您是否在清单中注册了PlacesMapActivity?我尝试了主活动。这并检查了PlacesMapActivity是否在清单中,但错误仍然相同。您必须将目标更改为类似以下内容:target=Google Inc.:Google API:8而不是android=android-8行110是Intent I=new Intent(getApplicationContext()),PlacesMapActivity.class);非常感谢您,当我从项目>属性>Java构建路径>库中删除maps.jar文件时,它可以正常工作
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