Hi *,
does anyone know why my code runs as Java code, but not for Android. I try to get a simple reader to run but the only effort i got is in Java. No luck with Android…
import java.net.MalformedURLException;
import java.net.URL;
import java.security.cert.Certificate;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;
public class HttpsClient{
public static void main(String[] args)
{
new HttpsClient().getTheContent();
}
private void getTheContent(){
String https_url = "https://api.spark.io/v1/devices/MYCOREID/events/?access_token=MYTOKEN";
URL url;
try {
url = new URL(https_url);
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
//dump all the content
print_content(con);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void print_content(HttpsURLConnection con){
if(con!=null){
try {
System.out.println("****** Spark Core - Result ********");
BufferedReader br =
new BufferedReader(
new InputStreamReader(con.getInputStream()));
String input;
while ((input = br.readLine()) != null){
System.out.println(input);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
When I try to use that in Android Studio I got an “Error: illegal start of expression” and “Error: ; expected” for the lines: private void testIt() { … }, private void print_https_cert(HttpsURLConnection con){ … } and private void print_content(HttpsURLConnection con){ … }.
Please do have merci with my Java skills, absolute new in that but willing to learn.