Results 1 to 19 of 19
- 12-31-2009, 10:58 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
cannot find main - it is there though
Hi,
I'm new to java and have run across a problem fairly soon after starting. Here's a bit of code I typed in. When I build the project, it does so with no issues. When I try to run it JCreator tells me it can find no 'main'. I checked everything but can find no fault in the syntax. Difficult language this after VB.
Any help much appreciated.
Thanks
import static java.lang.system.out;
import static java.lang.system.in;
import java.util.Scanner;
import java.util.Random;
class DTTTL {
public static void main(String args[]) {
Scanner myscanner = new Scanner(in);
out.print("Enter a number between 1 and 10");
int inputNumber = myscanner.nextInt();
int randomNumber = new Random.nextInt(10)+ 1;
if(randomNumber==inputNumber) {
out.println("*You win*);
}
out.println("That was a very good guess :-)");
out println("The random number was ");
out println(randomNumber + '.');
out println("Thanks for playing");
}
}
- 01-01-2010, 12:10 AM #2
My first attempt to compile your code resulted in:
Compiles okay now.Java Code:C:\jexp>javac DTTTL.java DTTTL.java:15: unclosed string literal out.println("*You win*); ^ DTTTL.java:18: ';' expected out println("The random number was "); ^ DTTTL.java:19: ';' expected out println(randomNumber + '.'); ^ DTTTL.java:19: not a statement out println(randomNumber + '.'); ^ DTTTL.java:19: ';' expected out println(randomNumber + '.'); ^ DTTTL.java:20: ';' expected out println("Thanks for playing"); ^ 6 errors
Java Code:import static java.lang.System.out; import static java.lang.System.in; import java.util.Scanner; import java.util.Random; class DTTTL { public static void main(String args[]) { Scanner myscanner = new Scanner(in); out.print("Enter a number between 1 and 10"); int inputNumber = myscanner.nextInt(); // Was missing the method operator "()" below: int randomNumber = new Random().nextInt(10)+ 1; if(randomNumber==inputNumber){ out.println("*You win*"); } out.println("That was a very good guess :-)"); // Missing "." operator below. // out println("The random number was "); // out println(randomNumber + '.'); // out println("Thanks for playing"); } }
- 01-01-2010, 12:37 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
Got it!
Thanks very much. Bloody syntax. Bummer.
Happy New Year to you
David
- 01-01-2010, 09:47 AM #4gcampton Guest
JCreator gives same error messages, just make sure you have task view opened. (should be open by default)
Last edited by gcampton; 01-01-2010 at 09:51 AM.
- 01-01-2010, 02:10 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Is that JCreator not highlighted/underline incorrect syntax?
- 01-02-2010, 12:23 AM #6
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
Jcreator
Hi,
My free version of JCreator does not highlight syntax errors in any way. Do you know of a free one that does? I need to progress a bit more before I fork out.
Thank you
David
- 01-02-2010, 03:20 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Use NetBeans. It have bunch of much useful features. Incorrect syntax highlighting is pretty cool.
- 01-02-2010, 03:26 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I think Eclipse do the same. But I don't know exactly, I've never use it. Check it out if you want to use. By my experience I recommended NetBeans.
- 01-03-2010, 02:03 AM #9
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
NetBeans
Been using NetBeans all day, it's brilliant.
Thanks very much
David
- 01-03-2010, 03:52 PM #10gcampton Guest
Does that Netbeans have automatic error alternatives... pfftt
use eclipse :P
- 01-03-2010, 08:25 PM #11
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
Hmmm...
Well Netbeans is much better than the free JCreator. Maybe I should try Eclipse as well.
Thanks for the heads up.
- 01-04-2010, 02:49 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-05-2010, 03:56 PM #13gcampton Guest
- 01-06-2010, 12:46 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-06-2010, 09:23 AM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Fight!
Fight!
Fight!
:)
- 01-06-2010, 01:27 PM #16gcampton Guest
- 01-06-2010, 01:29 PM #17gcampton Guest
ok now I'm just getting silly.
- 01-11-2010, 04:59 PM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-11-2010, 05:01 PM #19
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I agreed with you gcampton, that notepad is the best to dig into first step of Java. Working on with fundamentals on notepad helps a lot to improve skills in may ways. But working on with industrial level applications you must need an advance IDE, isn't it?
Similar Threads
-
Could not find main class
By Andyj in forum New To JavaReplies: 2Last Post: 10-06-2009, 12:47 AM -
Cannot find Main class in Linux OS
By msskiran in forum EclipseReplies: 0Last Post: 04-10-2009, 02:04 AM -
Could not find main class - JDK 1.6
By Syranno in forum New To JavaReplies: 1Last Post: 07-25-2008, 04:07 PM -
JVM Could not find main class
By banduskank in forum Advanced JavaReplies: 2Last Post: 06-24-2008, 08:05 AM -
problems to find the main method
By christina in forum EclipseReplies: 2Last Post: 08-06-2007, 07:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks