2012-11-27 82 views
0

即時通訊嘗試在Android設備中使用GCM測試推送通知。只要我用一堆可用的stackoverflow運行服務器端測試。但我得到java.lang.NoClassDefFoundError:COM /大學/實體/ GCMTestingClientGCM的服務器端問題

import java.io.IOException; 

import com.google.android.gcm.server.Message; 
import com.google.android.gcm.server.Result; 
import com.google.android.gcm.server.Sender; 

public class GCMTestingClient { 
    public String GCMTest() throws IOException { 
     Sender sender = new Sender("AszEaAipXqOJl--lMKSk6qHiOO7zmavU3cRQPk"); 
     Message message = new Message.Builder() 
       .collapseKey("1") 
       .timeToLive(3) 
       .delayWhileIdle(true) 
       .addData("hello", 
         "this text will be seen in notification bar!!").build(); 

     Result result = sender.send(message, "93821834343", 1); 
     System.out.println("result" + result); 
     return result.toString(); 
    } 

    public static void main(String[] args) { 

     try { 
      GCMTestingClient gcm=new GCMTestingClient(); 
      gcm.GCMTest(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

} 

幫我解決這個問題。

錯誤消息:

java.lang.NoClassDefFoundError: com/univ/entity/GCMTestingClient 
Caused by: java.lang.ClassNotFoundException: com.univ.entity.GCMTestingClient 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252) 
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) 
Exception in thread "main" 

回答

1

是否正在運行使用

java com.univ.entity.GCMTestingClient 

應用程序?

如果是,那麼你在你的代碼的頂部缺少包名稱:

package com.univ.entity 

基本上,你的錯誤是說Java不能找到您要運行的類。您應該位於頂級目錄中,並使用GCMTestingClient類查看「com/univ/entity /」目錄。

+0

我已經包括** package com.univ.entity **;在類的頂部,我仍然得到了這個錯誤 –

+1

你重新編譯過類嗎?如何從命令行或ide運行代碼? – kenota

+0

其工作人員...只是我清理並運行它工作的項目:)謝謝你。 –