java.lang.NoClassDefFoundError:com.google.android.gms.gcm.GoogleCloudMessaging android

时间:2015-07-08 05:39:45

标签: android google-cloud-messaging google-play-services

朋友们,我想在我的应用中集成GCM,以便在我的应用中设置以下代码:

按钮点击通话功能

public void requestForGCM(final Context context ){
    try {
        new AsyncTask<Void, Void, String>() {
            protected void onPreExecute() {
                super.onPreExecute();
            };
            @Override
            protected String doInBackground(Void... params) {
                regid = null;
                try {
                    if (gcmObj == null) {
                        gcmObj = GoogleCloudMessaging.getInstance(context);
                    }
                    regid = gcmObj.register("SENDER_ID");
                    Log.w("", "Token >> "+regid);
                } catch (Exception e) {
                    Log.e("", "requestForGCM  >> "+e.toString());
                    return null;
                }
                return regid;
            }

            @SuppressLint("NewApi")
            @Override
            protected void onPostExecute(String result) {
                super.onPostExecute(result);

                try {
                    String GCMToken = result;
                    etRegId.setText(regid + "\n");

                } catch (Exception e) {
                    Log.e("", "onPostExecute >> "+e.toString());
                }

            }
        }.execute();
    } catch (Exception e) {
        Log.e("", "requestForGCM >> "+e.toString());
    }
 }

我将jar设置如下 enter image description here

enter image description here

enter image description here

当我运行上面的代码时,它给出了如下错误:

  Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging

编辑LOGCAT

07-08 11:37:20.193: E/AndroidRuntime(10385): FATAL EXCEPTION: AsyncTask #1
07-08 11:37:20.193: E/AndroidRuntime(10385): java.lang.RuntimeException: An error occured while executing doInBackground()
07-08 11:37:20.193: E/AndroidRuntime(10385):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at java.lang.Thread.run(Thread.java:856)
07-08 11:37:20.193: E/AndroidRuntime(10385): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging
07-08 11:37:20.193: E/AndroidRuntime(10385):    at pkg.android.rootways.worldofrental.FragmentDashboard$8.doInBackground(FragmentDashboard.java:1142)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at pkg.android.rootways.worldofrental.FragmentDashboard$8.doInBackground(FragmentDashboard.java:1)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-08 11:37:20.193: E/AndroidRuntime(10385):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

任何解决方案,我该如何解决这个问题?你的所有建议都适用

1 个答案:

答案 0 :(得分:0)

添加引用库时,我们只需要google-play-services_lib.jar.So我们需要从项目中删除库项目。

Project-&gt; Properties-&gt; javaBuildPath-&gt; Project-&gt; select google-play-services-&gt; remove。

清洁和建造。