Jump to content
  • 0

L2Network


cyta5

Question

Hello guys i have one problem with the vote manager at l2network, when the votes are until 999 the vote manager work

but when goes 1000 and up i got error because the website write the votes 1,000 with a comma.

maybe someone can help me to work this ?

ERROR RequestByPassToServer.runImpl : invalid number format
java.lang.NumberFormatException: For input string: "19,474"

the code is this 

public static int getL2NetworkVotes()
	{
		int votes = 0;
		boolean lineFound = false;
		try
		{
			URL url = new URL(Config.VOTES_SITE_L2NETWORK_URL);
			InputStream is = url.openStream();
			try (
				BufferedReader br = new BufferedReader(new InputStreamReader(is)))
			{
				String line;
				while ((line = br.readLine()) != null)
				{
					if (line.contains("color:#e7ebf2"))
						votes = Integer.parseInt(line.split(">")[2].split("<")[0]);
					lineFound = true;
				}
			}
		}
		catch (IOException e)
		{
			e.printStackTrace();
			System.out.println("NetWork is offline. We will check reward as it will be online again.");
		}
		if (!lineFound)
			System.out.println("The line wasn't found in Network, check site in case they updated.");
		return votes;
	}

 

Edited by cyta5
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Like @TGSLineage2 mentioned, you should replace "," with nothing. ""...

also, you have to add the lineFound inside of the line check. so it should be

while ((line = br.readLine()) != null)
{
	if (line.contains("color:#e7ebf2"))
	{
		votes = Integer.parseInt(line.split(">")[2].split("<")[0].replace(",",""));
		lineFound = true;
	}
}

 

Link to comment
Share on other sites

  • 0

  

4 hours ago, TGSLineage2 said:

line.split(">")[2].split("<")[0].replace(",","");

 

9 minutes ago, melron said:

Like @TGSLineage2 mentioned, you should replace "," with nothing. ""...

also, you have to add the lineFound inside of the line check. so it should be


while ((line = br.readLine()) != null)
{
	if (line.contains("color:#e7ebf2"))
	{
		votes = Integer.parseInt(line.split(">")[2].split("<")[0].replace(",",""));
		lineFound = true;
	}
}

 

 

but does not want and one check ...if the votes is <=999 or >999 ?

because the votes until the 999 its ok but when goes 1000 and over the website write it 1,000

Link to comment
Share on other sites

  • 0
43 minutes ago, cyta5 said:

  

 

 

but does not want and one check ...if the votes is <=999 or >999 ?

because the votes until the 999 its ok but when goes 1000 and over the website write it 1,000

You dont need any check. you replacing comma at every case and you are done

  • Upvote 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...