SRL Archive - Java Help and Tutorials

Java, Regex, no match problem


noway123

2012-08-27 15:47:06

Hi.

Iam working on a Runescapetool which includes a Highscoretool.

My goal is it to have the rank,xp and total lvl each in a seperate group which i want to find with a regex.

I tested it with this testString and testPattern on http://www.cis.upenn.edu/~matuszek/General/RegexTester/regex-tester.html and it did work.

String: 349,2496,1051249524 - JavaPattern: "(\\d+),(\\d+),(\\d+)" - Pattern: (\d+),(\d+),(\d+)

However i always get the "No match found" error when i do start my program.

The connection does work and in the variable "line" is the correct String. ( I debuged it several times). Iam really lost and can not find my mistake. Would be nice if someone could help.



The Methode which returns the stats for each skill.
The error is @ line 18 "skill.setRank…"
public HashMap<String, Skill> lookUpSkills(String name){
if(app.getPlayerUtil().doesPlayerExsist(name)) return app.getPlayerUtil().getPlayerByName(name).getSkills();
try {
HashMap<String, Skill> skills = new HashMap<String, Skill>();

URL url = new URL(Var.GET_SKILLS_BY_NAME + name);
URLConnection urlConnector = url.openConnection();
BufferedReader urlReader = new BufferedReader(new InputStreamReader(urlConnector.getInputStream()));

String line = null;
Matcher regexMatcher = null;
Skill skill = null;
int skillNamesCount = 0;

while((line = urlReader.readLine()) != null){
if((regexMatcher = Var.SKILL_SEARCH_PATTERN.matcher(line)) != null){
skill = new Skill();
skill.setRank(regexMatcher.group(1));
skill.setLvl(regexMatcher.group(2));
skill.setXp(regexMatcher.group(3));
skill.setName(Var.SKILL_NAMES[skillNamesCount]);
skills.put(skill.getName(), skill)
}
skillNamesCount++;
}

return skills;

} catch(Exception e){
System.out.println(""+e);
app.setDefaultPlayerAsCurrentPlayer();
System.out.println("Failed to lookup SKILLS.");
return null;
}
}

Public variables
public static final Pattern SKILL_SEARCH_PATTERN =
Pattern.compile("(\\d+),(\\d+),(\\d+)");

public static final String[] SKILL_NAMES = {"Attack", "Hitpoints", "Mining", "Strenght", "Agility", "Smithing", "Defence",
"Herblor", "Fishing", "Range", "Thiving", "Cooking", "Prayer", "Crafting",
"Firemaking", "Magic", "Fletching", "Woodcutting", "Runecrafting", "Slayer",
"Farming", "Construction", "Hunting", "Summoning", "Dungeoneering", "Total Lvl"};

public static final String GET_SKILLS_BY_NAME = "http://hiscore.runescape.com/index_lite.ws?player=";

Error
java.lang.IllegalStateException: No match found
Failed to lookup SKILLS.


Sry for my bad english :P

Noway123

Brandon

2012-08-27 17:04:44

Try using

[0-9]+

noway123

2012-08-27 17:10:42

From: Brandon
Try using

[0-9]+



Does not work - same error. Ill try to read all lines first and then find patterns.

Edit: Wow iam such an idiot. I forgot to search…

regexMatcher.find();