I've got the following error:
Exception in thread "main" java.lang.RuntimeException: java.net.MalformedURLException: no protocol: url
at test.getJsonFromUrl(test.java:67)
at test.main(test.java:75)
Caused by: java.net.MalformedURLException: no protocol: url
...
And this is my complete code:
import java.io.Reader;
import java.net.URL;
import com.google.gson.*;
import java.io.IOException;
import java.io.InputStreamReader;
public class test {
public static String getJsonFromUrl(String url){
Gson gson = new GsonBuilder().create();
try{
Reader reader = new InputStreamReader(new URL("url").openStream());
gson.fromJson(reader, String.class);
}catch(IOException e){
throw new RuntimeException(e);
}
return gson.toString();
}
public static void main(String[] args) {
String json = getJsonFromUrl("https://api.kraken.com/0/public/Assets?asset=XBT");
System.out.println(json);
}
}
Dont know where the problem is, because if i copy the url in my browser it shows me JSON content... I gues it is an url? How could i fix it?
Okay i changed both and im gettin' the following output:
And so on (its not the complete output). And this is my code: