Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Find the Error in Class Code

    Hello. I copying some code for a class from a text on Java. Even though I beleive I have gotten the code correct, I get error messages, Can anyone helps me resolve this?

    The code:
    Java Code:
    public class Primefinder implements Runnable {
    	public long target;
    	public long prime;
    	public boolean finished = false;
    	private Thread runner;
    
    	PrimeFinder(long inTarget) {
    		target = inTarget;
    		if (runner == null) {
    			runner = new Thread(this);
    			runner.start();
    		}
    	}
    
    	public void run() {
    		long numPrime = 0;
    		long candidates = 2;
    		while (numPrime < target) {
    			if (isPrime(candidate)) {
    				numPrimes++;
    				prime = candidate;
    			}
    			candidate++;
    		}
    		finished = true;
    	}
    	
    	boolean isPrime(long checkNumber) {
    		double root = Math.sqrt(checkNumber);
    		for (int i =2; i <= root; i++) {
    			if (checkNumber % i == 0)
    				return false;
    		}
    		return true;
    	}
    }
    The error messages on compiling:
    "invalid method declaration; return type required"
    "PrimeFinder(long inTarget) {'

    Thank you.

  2. #2
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Java is case sensitive - look at the class name and the constructor name.
    The f is in a different case

  3. #3
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    Hi
    you are declaring Primefinder class constructor PrimeFinder .F should be in small case i.e. exactly same as class name

  4. #4
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default

    Hello. Aha, I got it. Thank you for showing me what I did wrong. Bogie.

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2011, 10:48 PM
  2. runtime error 'could not find main class' ?
    By ruud00000 in forum Java Applets
    Replies: 5
    Last Post: 12-31-2010, 06:58 PM
  3. [SOLVED] Could not find the main class: error...
    By bobleny in forum New To Java
    Replies: 21
    Last Post: 03-02-2010, 11:53 AM
  4. Replies: 1
    Last Post: 07-03-2009, 09:41 PM
  5. cannot find symbol class error
    By po0oker in forum New To Java
    Replies: 5
    Last Post: 10-31-2007, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •