# Java - illegal start of expression



## TimeShift (Feb 5, 2011)

Hello, Could you help me fixing this error ? i was trying to make a vote code.

Note:I'm new in programming. 


```
public void initialize() {
[COLOR=Red]        public boolean checkVotes(String playerName) {
                try {
                        String urlString = "http://xxxxxx.com/vote.php?type=checkvote&username="+playerName;
                        urlString = urlString.replaceAll(" ", "%20");
                        URL url = new URL(urlString);
                        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                        String results = reader.readLine();
                        if(results.length() > 0) {
                                if(results.equals("user needs reward..."))
                                        return true;
                                else
                                        return false;
                        }
                } catch (MalformedURLException e) {
                        System.out.println("Malformed URL Exception in checkVotes(String playerName)");
                } catch (IOException e) {
                        System.out.println("IO Exception in checkVotes(String playerName)");
                }
                return false;
        }[/COLOR]

        synchronized (this) {
            outStream.createFrame(249);
            outStream.writeByteA(1);        // 1 for members, zero for free
            outStream.writeWordBigEndianA(playerId);
            for (int j = 0; j < Server.playerHandler.players.length; j++) {
                if (j == playerId)
                    continue;
                if (Server.playerHandler.players[j] != null) {
                    if (Server.playerHandler.players[j].playerName.equalsIgnoreCase(playerName))
                        disconnected = true;
                }
            }
```
THE RED CODE:the code i made

after compiling :


```
src\server\model\players\Client.java:277: illegal start of expression
        public boolean checkVotes(String playerName); {
        ^
src\server\model\players\Client.java:277: ';' expected
        public boolean checkVotes(String playerName); {
                                 ^
src\server\model\players\Client.java:277: ';' expected
        public boolean checkVotes(String playerName); {
                                                   ^
3 errors
Press any key to continue . . .
```


----------



## andythepandy (Jul 2, 2006)

The reason you are getting an illegal start error is that you have a method inside of another method which isn't allowed. Place your code in red above or below the initialize function and then see what happens


----------



## TimeShift (Feb 5, 2011)

i tried 

could you do it for me please ?

http://paste.rune-server.org/1514

where to put ?


----------



## andythepandy (Jul 2, 2006)

Well, all you need to do is put the method checkVotes above the method initialize:


```
public boolean checkVotes(String playerName) {
	try {
		String urlString = "http://xxxxxx.com/vote.php?type=checkvote&username="+playerName;
		urlString = urlString.replaceAll(" ", "%20");
		URL url = new URL(urlString);
		BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
		String results = reader.readLine();
		if(results.length() > 0) {
			if(results.equals("user needs reward..."))
				return true;
			else
				return false;
		}
	} catch (MalformedURLException e) {
		System.out.println("Malformed URL Exception in checkVotes(String playerName)");
	} catch (IOException e) {
		System.out.println("IO Exception in checkVotes(String playerName)");
	}
	return false;
}

public void initialize() {
	synchronized (this) {
	outStream.createFrame(249);
	outStream.writeByteA(1);        // 1 for members, zero for free
	outStream.writeWordBigEndianA(playerId);
	for (int j = 0; j < Server.playerHandler.players.length; j++) {
	if (j == playerId)
		continue;
	if (Server.playerHandler.players[j] != null) {
		if (Server.playerHandler.players[j].playerName.equalsIgnoreCase(playerName))
			disconnected = true;
	}
}
```


----------



## TimeShift (Feb 5, 2011)

```
src\server\model\players\Client.java:280: cannot find symbol
symbol  : class URL
location: class server.model.players.Client
                URL url = new URL(urlString);
                ^
src\server\model\players\Client.java:280: cannot find symbol
symbol  : class URL
location: class server.model.players.Client
                URL url = new URL(urlString);
                              ^
src\server\model\players\Client.java:281: cannot find symbol
symbol  : class BufferedReader
location: class server.model.players.Client
                BufferedReader reader = new BufferedReader(new InputStreamReader
(url.openStream()));
                ^
src\server\model\players\Client.java:281: cannot find symbol
symbol  : class BufferedReader
location: class server.model.players.Client
                BufferedReader reader = new BufferedReader(new InputStreamReader
(url.openStream()));
                                            ^
src\server\model\players\Client.java:281: cannot find symbol
symbol  : class InputStreamReader
location: class server.model.players.Client
                BufferedReader reader = new BufferedReader(new InputStreamReader
(url.openStream()));
                                                               ^
src\server\model\players\Client.java:289: cannot find symbol
symbol  : class MalformedURLException
location: class server.model.players.Client
        } catch (MalformedURLException e) {
                 ^
src\server\model\players\Client.java:291: cannot find symbol
symbol  : class IOException
location: class server.model.players.Client
        } catch (IOException e) {
                 ^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
7 errors
Press any key to continue . . .
```


----------



## andythepandy (Jul 2, 2006)

It's complaining that it can't find any of the classes you're using, so you need to import them at the top of the code:


```
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.io.IOException;
```


----------

