I have built a program in java, and running it in IntelliJ is fine, but when I build the artifact (jar) and run it in the command prompt on my computer, it throws the IllegalArgumentException
.
I am using java-json.jar
as my library to make a string (that is in JSON form) into a JSON object so that I can iterate through it and display the information as needed.
Here are the results of running the program in CMD:
C:\Users\DeskTop\IdeaProjects\OperationGamerProfile\out\artifacts\OperationGamerProfile_jar>java -jar OperationGamerProfile.jar
Thank you for choosing Operation Gamer Profile!
Please read the manual that was provided with this tool so that you know how to use it...
Lets get started...
The client ID is: (My client ID)
The client Secret is: (My client secret)
Please enter your authorization token(This is CASE SENSITIVE): (my token)
Result from blizzard: {"characters":[{"name":"Netherfry","realm":"Bleeding Hollow","battlegroup":"Ruin","class":5,"race":8,"gender":0,"level":5,"achievementPoints":0,"thumbnail":"bleeding-hollow/27/163571995-avatar.jpg","lastModified":0},{"name":"Netherwarz","realm":"Darkspear","battlegroup":"Cyclone","class":9,"race":5,"gender":0,"level":5,"achievementPoints":0,"thumbnail":"darkspear/130/86434434-avatar.jpg","guild":"GeekyGaming","guildRealm":"Darkspear","lastModified":0},{"name":"Hailnether","realm":"Akama","battlegroup":"Reckoning","class":1,"race":2,"gender":0,"level":2,"achievementPoints":0,"thumbnail":"akama/235/95051243-avatar.jpg","lastModified":0},{"name":"Hailnether","realm":"Khaz Modan","battlegroup":"Cyclone","class":2,"race":10,"gender":0,"level":1,"achievementPoints":0,"thumbnail":"khaz-modan/53/101812021-avatar.jpg","lastModified":0},{"name":"Hailne6EA459","realm":"Greymane","battlegroup":"Shadowburn","class":5,"race":11,"gender":0,"level":0,"achievementPoints":0,"thumbnail":"greymane/89/91137113-avatar.jpg","lastModified":0},{"name":"Netherdrew","realm":"Bleeding Hollow","battlegroup":"Ruin","class":11,"race":8,"gender":0,"level":91,"achievementPoints":1470,"thumbnail":"bleeding-hollow/134/156092806-avatar.jpg","spec":{"name":"Guardian","role":"TANK","backgroundImage":"bg-druid-bear","icon":"ability_racial_bearform","description":"Takes on the form of a mighty bear to absorb damage and protect allies.\r\n\r\nPreferred Weapon: Staff, Polearm","order":2},"guild":"EndlessVoid","guildRealm":"Bleeding Hollow","lastModified":1429907056000},{"name":"Hailnether","realm":"Wyrmrest Accord","battlegroup":"Cyclone","class":3,"race":4,"gender":0,"level":3,"achievementPoints":0,"thumbnail":"wyrmrest-accord/146/109003154-avatar.jpg","lastModified":0},{"name":"Netherwraith","realm":"Bleeding Hollow","battlegroup":"Ruin","class":9,"race":10,"gender":0,"level":16,"achievementPoints":1305,"thumbnail":"bleeding-hollow/72/157163336-avatar.jpg","spec":{"name":"Affliction","role":"DPS","backgroundImage":"bg-warlock-affliction","icon":"spell_shadow_deathcoil","description":"A master of shadow magic who specializes in drains and damage-over-time spells.\r\n\r\nPreferred Weapon: Staff, Wand, Dagger, Sword","order":0},"lastModified":1411674035000},{"name":"Nethermonk","realm":"Bleeding Hollow","battlegroup":"Ruin","class":10,"race":10,"gender":0,"level":1,"achievementPoints":0,"thumbnail":"bleeding-hollow/13/157523981-avatar.jpg","lastModified":0},{"name":"Netherhunt","realm":"Bleeding Hollow","battlegroup":"Ruin","class":3,"race":2,"gender":0,"level":11,"achievementPoints":1380,"thumbnail":"bleeding-hollow/245/163559157-avatar.jpg","spec":{"name":"Marksmanship","role":"DPS","backgroundImage":"bg-hunter-marksman","icon":"ability_hunter_focusedaim","description":"A master sharpshooter who excels in bringing down enemies from afar.\r\n\r\nPreferred Weapon: Bow, Crossbow, Gun","order":1},"guild":"EndlessVoid","guildRealm":"Bleeding Hollow","lastModified":1425762452000},{"name":"Netherlock","realm":"Cho'gall","battlegroup":"Vindication","class":9,"race":10,"gender":0,"level":16,"achievementPoints":0,"thumbnail":"chogall/88/110060376-avatar.jpg","guild":"Mindless","guildRealm":"Cho'gall","lastModified":0},{"name":"Bi?¬zzard","realm":"Bloodhoof","battlegroup":"Ruin","class":1,"race":2,"gender":0,"level":1,"achievementPoints":0,"thumbnail":"bloodhoof/42/108061994-avatar.jpg","lastModified":0},{"name":"Netherman","realm":"Cho'gall","battlegroup":"Vindication","class":3,"race":10,"gender":0,"level":20,"achievementPoints":1370,"thumbnail":"chogall/223/109983711-avatar.jpg","spec":{"name":"Marksmanship","role":"DPS","backgroundImage":"bg-hunter-marksman","icon":"ability_hunter_focusedaim","description":"A master sharpshooter who excels in bringing down enemies from afar.\r\n\r\nPreferred Weapon: Bow, Crossbow, Gun","order":1},"guild":"IliilBARCODEliilI","guildRealm":"Cho'gall","lastModified":1425698021000},{"name":"Yoursbaby","realm":"Moon Guard","battlegroup":"Reckoning","class":5,"race":1,"gender":1,"level":1,"achievementPoints":0,"thumbnail":"moon-guard/213/116473301-avatar.jpg","lastModified":0},{"name":"Hailne652387","realm":"Bladefist","battlegroup":"Vengeance","class":5,"race":11,"gender":0,"level":2,"achievementPoints":0,"thumbnail":"bladefist/135/107291527-avatar.jpg","lastModified":0},{"name":"Aazzdf","realm":"Bleeding Hollow","battlegroup":"Ruin","class":1,"race":2,"gender":1,"level":1,"achievementPoints":0,"thumbnail":"bleeding-hollow/145/164662417-avatar.jpg","lastModified":0},{"name":"Nethersquad","realm":"Bleeding Hollow","battlegroup":"Ruin","class":10,"race":10,"gender":0,"level":0,"achievementPoints":0,"thumbnail":"bleeding-hollow/36/157524004-avatar.jpg","lastModified":0},{"name":"Darknether","realm":"Bleeding Hollow","battlegroup":"Ruin","class":6,"race":10,"gender":0,"level":62,"achievementPoints":1380,"thumbnail":"bleeding-hollow/118/156625270-avatar.jpg","spec":{"name":"Unholy","role":"DPS","backgroundImage":"bg-deathknight-unholy","icon":"spell_deathknight_unholypresence","description":"A master of death and decay, spreading infection and controlling undead minions to do his bidding.\r\n\r\nPreferred Weapon: Two-Handed Axe, Mace, Sword","order":2},"lastModified":1425841594000},{"name":"Lpeodke","realm":"Hellscream","battlegroup":"Rampage","class":5,"race":1,"gender":1,"level":1,"achievementPoints":0,"thumbnail":"hellscream/115/106721395-avatar.jpg","lastModified":0}]}
Starting JSONObjects
java.lang.IllegalArgumentException
at sun.net.www.ParseUtil.decode(Unknown Source)
at sun.misc.URLClassPath$JarLoader.<init>(Unknown Source)
at sun.misc.URLClassPath$3.run(Unknown Source)
at sun.misc.URLClassPath$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath.getLoader(Unknown Source)
at sun.misc.URLClassPath.getLoader(Unknown Source)
at sun.misc.URLClassPath.getNextLoader(Unknown Source)
at sun.misc.URLClassPath.getResource(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.OperationGamerProfile.Main.main(Main.java:52)
C:\Users\DeskTop\IdeaProjects\OperationGamerProfile\out\artifacts\OperationGamerProfile_jar>
Here is the htmlGetRequest
method:
private static String htmlGetRequest(String urlToRead) throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL(urlToRead);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
return result.toString();
}
Here is the code with the JSON:
try {
//getting data
String result = htmlGetRequest(url);
System.out.println("Result: " + result);
System.out.println();
System.out.println("Starting JSONObjects");
***//ERROR STARTS HERE***
JSONObject jsonobject = new JSONObject(result);
System.out.println("Built object");
JSONArray jsonArray = jsonobject.getJSONArray("characters");
System.out.println("Built Array");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject explrObject = jsonArray.getJSONObject(i);
String gender;
if (explrObject.get("gender").toString().equals("0")) {
gender = "Male";
} else {
gender = "Female";
}
String charClass = "";
switch(explrObject.get("class").toString()) {
case "1": charClass = "Warrior"; break;
case "2": charClass = "Paladin"; break;
case "3": charClass = "Hunter"; break;
case "4": charClass = "Rogue"; break;
case "5": charClass = "Priest"; break;
case "6": charClass = "Death Knight"; break;
case "7": charClass = "Shaman"; break;
case "9": charClass = "Mage"; break;
case "8": charClass = "Warlock"; break;
case "10": charClass = "Monk"; break;
case "11": charClass = "Druid"; break;
case "12": charClass = "Demon Hunter"; break;
}
System.out.printf("Information of character %d:\n" +
"\t Name: %s\n" +
"\t Level: %s\n" +
"\t Gender: %s\n" +
"\t Class: %s\n"
, i+1, explrObject.get("name"), explrObject.get("level"), gender, charClass);
System.out.println();
}
System.out.println("Done displaying JSON Data...\nExiting program...");
} catch(Exception e) {
e.printStackTrace();
}
At first I was getting NoClassDefFoundError
, and ended up finding the classpath in IntelliJ and pasted this into it: "set classpath=%classpath%;.;"
, that seemed to fix the problem of the class not being found, but led to the error of IllegalArgumentException
.
If anyone is able to help here, I would greatly appreciate it, if you need anymore details of the program, I am happy to provide them.
result
contains: Result from blizzard:
{"characters":[{"name":"Netherfry","realm":"Bleeding Hollow","battlegroup":"Ruin","class":5,"race":8,"gender":0,"level":5,"achievementPoints":0,"thumbnail":"bleeding-hollow/27/163571995-avatar.jpg","lastModified":0},{"name":"Netherwarz","realm":"Darkspear","battlegroup":"Cyclone","class":9,"race":5,"gender":0,"level":5,"achievementPoints":0,"thumbnail":"darkspear/130/86434434-avatar.jpg","guild":"GeekyGaming","guildRealm":"Darkspear","lastModified":0},{"name":"Hailnether","realm":"Akama","battlegroup":"Reckoning","class":1,"race":2,"gender":0,"level":2,"achievementPoints":0,"thumbnail":"akama/235/95051243-avatar.jpg","lastModified":0},{"name":"Hailnether","realm":"Khaz Modan","battlegroup":"Cyclone","class":2,"race":10,"gender":0,"level":1,"achievementPoints":0,"thumbnail":"khaz-modan/53/101812021-avatar.jpg","lastModified":0},{"name":"Hailne6EA459","realm":"Greymane","battlegroup":"Shadowburn","class":5,"race":11,"gender":0,"level":0,"achievementPoints":0,"thumbnail":"greymane/89/91137113-avatar.jpg","lastModified":0},{"name":"Netherdrew","realm":"Bleeding Hollow","battlegroup":"Ruin","class":11,"race":8,"gender":0,"level":91,"achievementPoints":1470,"thumbnail":"bleeding-hollow/134/156092806-avatar.jpg","spec":{"name":"Guardian","role":"TANK","backgroundImage":"bg-druid-bear","icon":"ability_racial_bearform","description":"Takes on the form of a mighty bear to absorb damage and protect allies.\r\n\r\nPreferred Weapon: Staff, Polearm","order":2},"guild":"EndlessVoid","guildRealm":"Bleeding Hollow","lastModified":1429907056000},{"name":"Hailnether","realm":"Wyrmrest Accord","battlegroup":"Cyclone","class":3,"race":4,"gender":0,"level":3,"achievementPoints":0,"thumbnail":"wyrmrest-accord/146/109003154-avatar.jpg","lastModified":0},{"name":"Nethermonk","realm":"Bleeding Hollow","battlegroup":"Ruin","class":10,"race":10,"gender":0,"level":1,"achievementPoints":0,"thumbnail":"bleeding-hollow/13/157523981-avatar.jpg","lastModified":0},{"name":"Netherwraith","realm":"Bleeding Hollow","battlegroup":"Ruin","class":9,"race":10,"gender":0,"level":16,"achievementPoints":1305,"thumbnail":"bleeding-hollow/72/157163336-avatar.jpg","spec":{"name":"Affliction","role":"DPS","backgroundImage":"bg-warlock-affliction","icon":"spell_shadow_deathcoil","description":"A master of shadow magic who specializes in drains and damage-over-time spells.\r\n\r\nPreferred Weapon: Staff, Wand, Dagger, Sword","order":0},"lastModified":1411674035000},{"name":"Netherhunt","realm":"Bleeding Hollow","battlegroup":"Ruin","class":3,"race":2,"gender":0,"level":11,"achievementPoints":1380,"thumbnail":"bleeding-hollow/245/163559157-avatar.jpg","spec":{"name":"Marksmanship","role":"DPS","backgroundImage":"bg-hunter-marksman","icon":"ability_hunter_focusedaim","description":"A master sharpshooter who excels in bringing down enemies from afar.\r\n\r\nPreferred Weapon: Bow, Crossbow, Gun","order":1},"guild":"EndlessVoid","guildRealm":"Bleeding Hollow","lastModified":1425762452000},{"name":"Netherlock","realm":"Cho'gall","battlegroup":"Vindication","class":9,"race":10,"gender":0,"level":16,"achievementPoints":0,"thumbnail":"chogall/88/110060376-avatar.jpg","guild":"Mindless","guildRealm":"Cho'gall","lastModified":0},{"name":"Biìzzard","realm":"Bloodhoof","battlegroup":"Ruin","class":1,"race":2,"gender":0,"level":1,"achievementPoints":0,"thumbnail":"bloodhoof/42/108061994-avatar.jpg","lastModified":0},{"name":"Netherman","realm":"Cho'gall","battlegroup":"Vindication","class":3,"race":10,"gender":0,"level":20,"achievementPoints":1370,"thumbnail":"chogall/223/109983711-avatar.jpg","spec":{"name":"Marksmanship","role":"DPS","backgroundImage":"bg-hunter-marksman","icon":"ability_hunter_focusedaim","description":"A master sharpshooter who excels in bringing down enemies from afar.\r\n\r\nPreferred Weapon: Bow, Crossbow, Gun","order":1},"guild":"IliilBARCODEliilI","guildRealm":"Cho'gall","lastModified":1425698021000},{"name":"Yoursbaby","realm":"Moon Guard","battlegroup":"Reckoning","class":5,"race":1,"gender":1,"level":1,"achievementPoints":0,"thumbnail":"moon-guard/213/116473301-avatar.jpg","lastModified":0},{"name":"Hailne652387","realm":"Bladefist","battlegroup":"Vengeance","class":5,"race":11,"gender":0,"level":2,"achievementPoints":0,"thumbnail":"bladefist/135/107291527-avatar.jpg","lastModified":0},{"name":"Aazzdf","realm":"Bleeding Hollow","battlegroup":"Ruin","class":1,"race":2,"gender":1,"level":1,"achievementPoints":0,"thumbnail":"bleeding-hollow/145/164662417-avatar.jpg","lastModified":0},{"name":"Nethersquad","realm":"Bleeding Hollow","battlegroup":"Ruin","class":10,"race":10,"gender":0,"level":0,"achievementPoints":0,"thumbnail":"bleeding-hollow/36/157524004-avatar.jpg","lastModified":0},{"name":"Darknether","realm":"Bleeding Hollow","battlegroup":"Ruin","class":6,"race":10,"gender":0,"level":62,"achievementPoints":1380,"thumbnail":"bleeding-hollow/118/156625270-avatar.jpg","spec":{"name":"Unholy","role":"DPS","backgroundImage":"bg-deathknight-unholy","icon":"spell_deathknight_unholypresence","description":"A master of death and decay, spreading infection and controlling undead minions to do her bidding.\r\n\r\nPreferred Weapon: Two-Handed Axe, Mace, Sword","order":2},"lastModified":1425841594000},{"name":"Lpeodke","realm":"Hellscream","battlegroup":"Rampage","class":5,"race":1,"gender":1,"level":1,"achievementPoints":0,"thumbnail":"hellscream/115/106721395-avatar.jpg","lastModified":0}]}`
Sorry for the spaghetti code...