rj
10-10-2013, 01:49 AM
Having trouble using 'between' in java...
I get this error:
Exception in thread "main" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Unknown Source)
at Highscores.main(Highscores.java:46)
with this code:
Pattern p = Pattern.compile("\\" + SkillsTSA[i] + "</a></td><td>.*\\</td><td>");
Matcher m = p.matcher(Source);
m.find();
System.out.println(SkillsTSA[i] + " " + m.group(1));
Whole source:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Highscores {
static String Source;
public static String getUrlSource(String url) throws IOException {
URL page = new URL(url);
URLConnection yc = page.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream(), "UTF-8"));
String inputLine;
StringBuilder a = new StringBuilder();
while ((inputLine = in.readLine()) != null)
a.append(inputLine);
in.close();
return a.toString();
}
public static void main(String args[]) {
String [] SkillsTSA = {
"Attack", "Defence", "Strength", "Hitpoints", "Ranged",
"Prayer", "Magic", "Cooking", "Woodcutting", "Fletching",
"Fishing", "Firemaking", "Crafting", "Smithing", "Mining",
"Herblore", "Agility", "Thieving", "Slayer", "Farming",
"Runecrafting", "Dungeoneering", "Summoning"
};
// String name = "";
try {
Source = getUrlSource("http://soulsplit.com/hs/index.php?name=advise");
} catch (IOException e) {
System.out.println("Error getting page source");
}
for (int i = 0; i < SkillsTSA.length; i++) {
Pattern p = Pattern.compile("\\" + SkillsTSA[i] + "</a></td><td>.*\\</td><td>");
Matcher m = p.matcher(Source);
m.find();
System.out.println(SkillsTSA[i] + " " + m.group(1));
}
}
}
why can't it find the inbetween string..
I get this error:
Exception in thread "main" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Unknown Source)
at Highscores.main(Highscores.java:46)
with this code:
Pattern p = Pattern.compile("\\" + SkillsTSA[i] + "</a></td><td>.*\\</td><td>");
Matcher m = p.matcher(Source);
m.find();
System.out.println(SkillsTSA[i] + " " + m.group(1));
Whole source:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Highscores {
static String Source;
public static String getUrlSource(String url) throws IOException {
URL page = new URL(url);
URLConnection yc = page.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream(), "UTF-8"));
String inputLine;
StringBuilder a = new StringBuilder();
while ((inputLine = in.readLine()) != null)
a.append(inputLine);
in.close();
return a.toString();
}
public static void main(String args[]) {
String [] SkillsTSA = {
"Attack", "Defence", "Strength", "Hitpoints", "Ranged",
"Prayer", "Magic", "Cooking", "Woodcutting", "Fletching",
"Fishing", "Firemaking", "Crafting", "Smithing", "Mining",
"Herblore", "Agility", "Thieving", "Slayer", "Farming",
"Runecrafting", "Dungeoneering", "Summoning"
};
// String name = "";
try {
Source = getUrlSource("http://soulsplit.com/hs/index.php?name=advise");
} catch (IOException e) {
System.out.println("Error getting page source");
}
for (int i = 0; i < SkillsTSA.length; i++) {
Pattern p = Pattern.compile("\\" + SkillsTSA[i] + "</a></td><td>.*\\</td><td>");
Matcher m = p.matcher(Source);
m.find();
System.out.println(SkillsTSA[i] + " " + m.group(1));
}
}
}
why can't it find the inbetween string..