我試圖用libGDX寫一點代碼來處理網絡。這裏是一個代碼:Gdx.net.sendHttpRequest中的NullPointerException
public class Test {
public static void main(String[] args) {
String accessToken = "********"; //a set of symbols, not important because it is specific of request target
String userID = "*********"; //also not important
String message = "Hello World";
String uri = "method/wall.post?owner_id=" + userID + "&message=" + message + "&access_token=" + accessToken;
HttpRequestBuilder requestBuilder = new HttpRequestBuilder();
HttpRequest httpRequest = requestBuilder.newRequest().method(HttpMethods.GET).url("https://api.vk.com/").content(uri).build();
Gdx.net.sendHttpRequest(httpRequest, //Here Eclipse shows NullPointerException
null); //But not here
}
如果我在瀏覽器中寫這個URL,它的工作原理是正確的。這意味着,這個問題在我身邊。如何解決它?
導致NullPointerException異常對象的值的總結:
你能發佈你的stacktrace嗎?有沒有給出「空」參數 – pL4Gu33
您是否使用過調試器? – Idos
可能重複[什麼是空指針異常,以及如何解決它?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do -i-fix-it) –