我对我的代码块有一些疑问。我尝试在Netbeans中运行它,它似乎不喜欢Google Glass上的这段代码。我使用Eclipse编译它,它似乎也正确编译。
package com.openglassquartz.helloglass;
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
public class OnlineRetrieval {
boolean activeGame;
public boolean checkGame() { //Method for which to check if there is a current game going on.
try {
URL url = new URL("http://danielchan.me/league/active.txt");
Scanner s = new Scanner(url.openStream()); //All errors point to this line of code??
int temporary_Reading = s.nextInt();
if(temporary_Reading == 1) {
return activeGame = true;
} else {
return activeGame = false;
}
} catch(IOException ex) {
ex.printStackTrace();
}
return activeGame;
}
}
来自LaunchService类。
OnlineRetrieval OR = new OnlineRetrieval();
boolean temp_Check = OR.checkGame();
01-14 16:38:32.187: E/AndroidRuntime(18639): at com.openglassquartz.helloglass.OnlineRetrieval.checkGame(OnlineRetrieval.java:20)
01-14 16:38:32.187: E/AndroidRuntime(18639): at com.openglassquartz.helloglass.CardLaunchService.onStartCommand(CardLaunchService.java:77)
我该如何解决这个问题?当我尝试输出它时,它似乎适用于Netbeans,但不适用于Google Glass。
答案 0 :(得分:0)
要看两件事(看起来您的帖子中的堆栈跟踪已被切断):
android.permission.INTERNET
权限添加到应用程序的清单中?AsyncTask
类作为处理此问题的方法。