Results 1 to 17 of 17
Thread: where is the class
- 02-04-2009, 06:40 AM #1
Member
- Join Date
- Apr 2008
- Posts
- 16
- Rep Power
- 0
where is the class
import java.awt.*;
import java.applet.Applet;
public class Rice extends Applet {
public void paint(Graphics g) {
int countOfSquares = 0;
int riceOnThisSquare = 1;
int totalRice = 0;
int y = 20;
do {
countOfSquares++;
g.drawString("On square "+countOfSquares+" are " +
riceOnThisSquare, 10, y);
totalRice = totalRice + riceOnThisSquare;
riceOnThisSquare = riceOnThisSquare * 2;
y = y +20;
} while (totalRice < 100);
g.drawString("Number of squares needed is " + countOfSquares,
10, y + 20);
}
}
it can find the class
- 02-04-2009, 07:14 AM #2
which exact error you get and when you get it ( compilation time/runtime ) ?
- 02-04-2009, 08:20 AM #3
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
i cant find any error in the code...
what class do you want?
- 02-04-2009, 08:41 AM #4
i'm guess you don't know what a class is?
in bold:
import java.awt.*;
import java.applet.Applet;
public class Rice extends Applet {
public void paint(Graphics g) {USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 02-04-2009, 11:46 AM #5
Member
- Join Date
- Apr 2008
- Posts
- 16
- Rep Power
- 0
thank for all answer.
angryboy, u r right <br>
public class Rice extends Applet {
the class doesnt declare yet how to correct the code
- 02-05-2009, 02:55 AM #6
I am sorry. Your question is not understandable. What are you trying to do?
- 02-05-2009, 04:17 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What you mean by class not declared. You have declared the class in your code. Seems you don't have any idea about what you are doing in that code.
Better to read more about Java classes.
Classes and Object : Suns' Tutorial.
- 02-05-2009, 04:18 AM #8
i'm guessing you don't know how to declare a class?
Rice bowl = new Rice();
bowl.someMethod(someParam);
you should read some intro on java. try googleling it.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 02-05-2009, 04:21 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 02-05-2009, 05:02 AM #10
- 02-05-2009, 05:18 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Never mind lol. Those simple things can misses anyone. But, it's much better to check twice before click the Submit button. Newbies can confuse.
- 02-05-2009, 07:10 AM #12
Member
- Join Date
- Apr 2008
- Posts
- 16
- Rep Power
- 0
import java.awt.*;
import java.applet.Applet;
public class Rice extends Applet {
public void paint(Graphics g) {
int countOfSquares = 0;
int riceOnThisSquare = 1;
int totalRice = 0;
int y = 20;
do {
countOfSquares++;
g.drawString("On square "+countOfSquares+" are " +
riceOnThisSquare, 10, y);
totalRice = totalRice + riceOnThisSquare;
riceOnThisSquare = riceOnThisSquare * 2;
y = y +20;
} while (totalRice < 100);
g.drawString("Number of squares needed is " + countOfSquares,
10, y + 20);
}
}
C:>javac rice.java
the error is shown
rice.java:4: class Rice is public, should be declared in a file named Rice.java
public class Rice extends Applet {
^
my question is "how to correct the code"
- 02-05-2009, 07:28 AM #13
Java is case-sensitive, rename your file "rice.java" => "Rice.java".
- 02-05-2009, 07:39 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In Java class name and the file name should be same. Since your Java class name is Rice the file name must be Rice.java. Not rice.java
- 02-05-2009, 07:53 AM #15
Member
- Join Date
- Apr 2008
- Posts
- 16
- Rep Power
- 0
C:>javac Rice.java
the error is shown
Exception in thread "main" java.lang.NoSuchMethodError: main
- 02-05-2009, 07:58 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
This an applet, you cannot run it with the command java. Once you use that command VM check the main method in your Java class, not found here and throw an exception.
Write a HTML code to execute this class file.
- 02-05-2009, 08:08 AM #17
pro85: why don't you try compiling some simple app first like a hello world program. just so you get the feel of a console.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Similar Threads
-
problem calling function from class to class
By alin_ms in forum New To JavaReplies: 3Last Post: 12-19-2008, 07:35 PM -
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM -
Able to find class file in WEB-INF/classes but not after add sub folders in class dir
By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM -
Class Reflection: Finding super class names
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:12 PM -
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks