我试图运行GCM示例应用程序,但我在我的logcat中面临致命异常(我的应用程序被迫关闭)它表明服务器URL链接是无效的URL。如果我运行我的URL链接显示“没有设备注册”。如果无效的URL意味着它显示错误,但它显示“没有设备注册”。所以我很困惑。为什么我要面对这个问题。
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
答案 0 :(得分:1)
导致“无效网址:192.168.1.2:8080 / home / register”... 看来你还没有上传代码到网络服务器。您必须上传服务器代码Live服务器。
答案 1 :(得分:1)
请记住,方法ServerUtilities.register(..)
在这里是静态的,并将RegId作为参数并将此Id注册到服务器。你必须在这个方法中执行你的代码,就像我们使用GET或POST方法将任何String发布到我们的服务器一样:
在执行代码之后,您的方法将如下所示:
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) {
}
}
答案 2 :(得分:1)
您的设备尚未注册,因为提供的服务器网址错误。请检查并提供有效的网址。