2013-03-04 82 views
0

我試圖運行GCM示例應用程序,但我在我的logcat中遇到致命異常(我的應用程序被強制關閉)它表明服務器URL鏈接是無效的URL。如果我運行我的URL鏈接,顯示「沒有註冊設備」。如果URL無效表示它顯示錯誤,但顯示「沒有設備註冊」。所以我很困惑。爲什麼我面臨這個問題。Android服務器註冊時的Google Cloud消息傳遞問題?

的logcat:

03-04 16:28:11.691: E/AndroidRuntime(770): FATAL EXCEPTION: AsyncTask #1 
03-04 16:28:11.691: E/AndroidRuntime(770): java.lang.RuntimeException: An error occured while executing doInBackground() 
03-04 16:28:11.691: E/AndroidRuntime(770): at android.os.AsyncTask$3.done(AsyncTask.java:299) 
03-04 16:28:11.691: E/AndroidRuntime(770): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 
03-04 16:28:11.691: E/AndroidRuntime(770): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 
03-04 16:28:11.691: E/AndroidRuntime(770): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 
03-04 16:28:11.691: E/AndroidRuntime(770): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
03-04 16:28:11.691: E/AndroidRuntime(770): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
03-04 16:28:11.691: E/AndroidRuntime(770): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
03-04 16:28:11.691: E/AndroidRuntime(770): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
03-04 16:28:11.691: E/AndroidRuntime(770): at java.lang.Thread.run(Thread.java:856) 
03-04 16:28:11.691: E/AndroidRuntime(770): Caused by: java.lang.IllegalArgumentException: invalid url: 192.168.1.2:8080/home/register 
03-04 16:28:11.691: E/AndroidRuntime(770): at com.google.android.gcm.demo.app.ServerUtilities.post(ServerUtilities.java:138) 
03-04 16:28:11.691: E/AndroidRuntime(770): at com.google.android.gcm.demo.app.ServerUtilities.register(ServerUtilities.java:66) 
03-04 16:28:11.691: E/AndroidRuntime(770): at com.google.android.gcm.demo.app.DemoActivity$2.doInBackground(DemoActivity.java:88) 
03-04 16:28:11.691: E/AndroidRuntime(770): at com.google.android.gcm.demo.app.DemoActivity$2.doInBackground(DemoActivity.java:1) 
03-04 16:28:11.691: E/AndroidRuntime(770): at android.os.AsyncTask$2.call(AsyncTask.java:287) 
03-04 16:28:11.691: E/AndroidRuntime(770): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
03-04 16:28:11.691: E/AndroidRuntime(770): ... 5 more 

代碼: http://paste.org/62112

回答

1

它的事業 「無效網址:192.168.1.2:8080/home/register」 ...... 看來你沒有上傳代碼到網絡服務器呢。你必須上傳服務器代碼Live服務器。

1

請記住,這裏的方法ServerUtilities.register(..)是靜態的,將RegId作爲參數並將此ID註冊到服務器。你必須做你的代碼在這種方法同樣像我們公佈任何字符串到我們的GET或POST方法服務器:

你的方法看起來像這樣的代碼後如下:

static boolean register(final Context context, final String regId) { 

     String URL = CommonUtilities.SERVER_URL+"&device=" + regId; 

     Log.v("URL : ", URL); 
     JSONObject json = fetchTwitterPublicTimeline(URL); 

     try { 
      Log.i("Json : ", json.toString()); 
      String login_msg = json.getString("MESSAGE"); 
      Log.i("Reply : ", login_msg); 
     } catch (Exception e) { 

     } 
} 
1

您設備尚未註冊,因爲給出的服務器URL是錯誤的。請檢查並提供有效的網址。

相關問題