アプリ版:「スタンプのみでお礼する」機能のリリースについて

JSONの中身をURL型のurlという変数に格納して、その中身を見たいのですが「String.valueOf」を使いデバックモードでブレークポイントを設定すれば変数の中身が見れると思うのですがコンソールに何も現れないのですが何か対処法御座いましたらご教授願います。

状況
URL url = new URL("http://www.ekidata.jp/api/l/11302.json");
URL型の変数urlにJSONデータサイトを格納している。

環境
アンドロイドスタジオ2.3
Java

JSONObject json = new JSONObject(String.valueOf(url));を使い
変数url格納したJSONデータをコンソール上で確認したい。
その為にはデバッグモードを使いブレークポイントを設定すれば見られるのではないか?と考えているがコンソール上に反映されない。

TestService.java

package jp.co.mocosuku.phr.service;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class TestService {
public static void executeGet(){
// ...
SubThread sub = new SubThread();
sub.start();
}
}

class SubThread extends Thread{
public void run(){
// executeGet() の中身をここに移動させる
System.out.println("===== HTTP GET Start =====");
try {
URL url = new URL("http://www.ekidata.jp/api/l/11302.json");
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
JSONObject json = new JSONObject(String.valueOf(url));
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
try (InputStreamReader isr = new InputStreamReader(connection.getInputStream(),
StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(isr)) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}
} finally {
if (connection != null) {
connection.disconnect();
}
}
} catch (JSONException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("===== HTTP GET End =====");

}
}

A 回答 (1件)

コンソールアプリ作りたいなら、IDEの選択間違ってます。


eclipse, netbeans, intellij idea などを使いましょう。
android studio は androidアプリを作るための専用IDEです。
    • good
    • 1

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!