-1

I hope all is well with you guys. I've been messing about with some Java recently, attempting to get data from an XML Link, and parsing the dat I need from it using a BufferedInputStream. I've done some searching here on Stack O.F -- and came up with this link. How to retrieve XML/RDF data from a dbpedia link or URL?

Pretty handy, and a lot of my code is based upon that. Slight problem though, somewhere along the way my program is catching an error. I have no idea why, and I was hoping you guys could help me out.

//import statements;

import java.io.*;
import java.util.Scanner;
import java.net.URL;
import java.net.HttpURLConnection;
import java.net.*;


public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String url = "http://http://battlecc5.evony.com/default.html?logfile/20171113/7d/42/7d42c3c3c89a7de4ec58c1ed0e66fbb1.xml";
    try{
    URL urlObj = new URL(url);
            System.out.println("URL Reached");
        try{
            java.net.HttpURLConnection connection = (HttpURLConnection)urlObj.openConnection();
                    System.out.println("Connection Successful");
            try{
                    InputStream reader = new BufferedInputStream(connection.getInputStream());
                        BufferedReader breader = new BufferedReader(new InputStreamReader(reader));
                        String line;    

                           while((line = breader.readLine()) != null){
                               System.out.println(line);
                           }
                        connection.disconnect();
                        System.out.println("Closed");
            }
            catch(IOException e){System.out.println("Fail 1");}
        }
        catch(IOException e){System.out.println("Fail 2");}
    }
    catch(MalformedURLException e){System.out.println("Failed 3");}
    System.out.println("Reached the End");
}

private boolean isDraftable(int modValue, int input){
    boolean success = false; // Default value
    int num = (int)(input/modValue);
    if((num % 2) == 0){
        //Is Even
        success = true; // isDraftable(true)
    }
    else{
        success = false; // !isDraftable(true)
    }
    return success;
}

private void HCDraft(int input){
    int draftFive = input/20;

    //System.out.println("HC Draft: %d", draftFive);    
}

private void CDraft(int input){
    int draftTen = input/10;

    //System.out.println("Colony Draft: %d", draftTen);
}


}

It isn't complete yet, but once the connection is made, it should just be ouputting what it's finding. Later, I'll be parsing it and doing calculations and whatnot with it (The 3 private functions are there for this purpose. They're just not being used right now.)

Input, feedback? Am I barking up the wrong tree? Cheers

  • 1
    Please post the error you're getting. Edit: Your URL string has `http://` in it twice - surely that's a mistake? – jsheeran Nov 20 '17 at 13:54
  • And what's the problem aside from the wrong URL? Is any of the "Fail 1" things printed? "somewhere along the way my program is catching an error" doesn't give us enough info to find out more. – f1sh Nov 20 '17 at 14:00
  • Jsheeran got it ). Mindless mistakes at 8am in the morning. Program will use a scanner for input in the future. Hence, just a copy and mistake error. – Michael Redbourne Nov 20 '17 at 14:37

1 Answers1

0

Yep.. So indeed there was an error in the URL. Curious to know why it wouldn't have failed on a malformedURLException. Its also important to note I was using an online compiler, so I have fixed the naming error (C programming habits).

Program works.. Just doesn't get what I need it to actually get. (The actual link that gets the other files must be elsewhere. Weird habits they have..)

Thanks jsheeran for pointing out the URL!