Page 2 of 2 FirstFirst 12
Results 21 to 38 of 38
  1. #21
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    Fubarable is right. There must be no error.
    public void Draw(Graphics g) //error is here
    {...}
    How can you be sure that error is in this line. Did the compiler pointed there.
    Looking back to your 1st post and others, I say you have changed your code.
    You made change to Draw() method, to Draw(Graphics g), so did you also changed code where this method is called.

    -Regards

  2. #22
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,310
    Blog Entries
    7
    Rep Power
    20

    Default

    In C++ you declare a function (usually in a .h or .hpp file) and define it somewhere else (in a .cpp or .cxx file). The declaration is a 'prototype' and looks something like this:

    Java Code:
    public void Draw(Graphics g);
    Not so in Java, you can only define methods in a class and they're always a member method; a definition looks like this in Java:

    Java Code:
    public void Draw(Graphics g) {
       // body of the method here ...
    }
    I suspect the OP still has a 'declaration' of a method somewhere; the Java compiler treats it as an abstract method and complains its heart out ...

    kind regards,

    Jos

  3. #23
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    You should not argue with java gurus,
    try changing :
    Java Code:
    	class Ball
    	{
    		public int size;
    		public int x_pos;
    		public int y_pos;
    		public void Draw();
    	}
    to
    Java Code:
    	class Ball
    	{
    		public int size;
    		public int x_pos;
    		public int y_pos;
    		public Ball(){
    			Draw();
    		}
    	}

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default

    The OP needs to say if he is trying to define a method named Draw or if he is trying to call a method named Draw. I think it's the former, but his c coding experience is getting it fouled up.

  5. #25
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by Norm View Post
    The OP needs to say if he is trying to define a method named Draw or if he is trying to call a method named Draw. I think it's the former, but his c coding experience is getting it fouled up.
    Or maybe he was trying to make an interface?

  6. #26
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    I fixed it, but I don't really remember how because I fell asleep soon after that, but now I have an error saying: reached end of code while parsing
    }
    ^


    Thats exactly what it said so any fixes?

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default

    Add some more }s
    You could have mismatched {}s
    Use some editor that has a "FindMatching" function and make sure your {} are paired.

  8. #28
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    I know one that I don't have downloaded and I just can't remember it right now, its killing me, can you tell me one?

  9. #29
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    Well now I'm up to 8 errors but I fixed the missing }. I'm going to post the block of code where it is and just put comments where the errors are.

    Java Code:
    class Ball
    {
    	public int size = 10;
    	public int x_pos = 50;
    	public int y_pos = 50;
    	public Ball(){
    		draw();//java.awt.Graphics cannot be applied to ()
    	}
    }
    
    
    public void run ()
    {
    	Ball One;
    	One.size = 10;
    	One.x_pos = 50;
    	One.y_pos = 50;
    	draw();//java.awt.Graphics cannot be applied to ()
    	}
    
    public void draw(Graphics g)
    {
    	g.setColor  (Color.red);
    
    	g.fillOval (x_pos - size, y_pos - size, 2 * size, 2 * size);
    //can't find any variables in the g.fillOval
    }

  10. #30
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by pizzadude223 View Post
    Well now I'm up to 8 errors but I fixed the missing }. I'm going to post the block of code where it is and just put comments where the errors are.

    Java Code:
    class Ball
    {
    	public int size = 10;
    	public int x_pos = 50;
    	public int y_pos = 50;
    	public Ball(){
    		draw();//java.awt.Graphics cannot be applied to ()
    	}
    }
    
    
    public void run ()
    {
    	Ball One;
    	One.size = 10;
    	One.x_pos = 50;
    	One.y_pos = 50;
    	draw();//java.awt.Graphics cannot be applied to ()
    	}
    
    public void draw(Graphics g)
    {
    	g.setColor  (Color.red);
    
    	g.fillOval (x_pos - size, y_pos - size, 2 * size, 2 * size);
    //can't find any variables in the g.fillOval
    }
    They are all there I guess?

  11. #31
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    Yep, all six variables and the two draw()'s.

  12. #32
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default

    Please post the full text of the error messages.
    I don't understand your edited versions of the error messages.

    What class are the run() and draw() methods supposed to be in?
    They are outside of the Ball class.

  13. #33
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    Sorry my bad. I fixed some things I think. I removed the run method and moved the stuff in it. Now I just have these errors, and I'm compiling in command prompt so this is exactly what it gives me:
    Java Code:
    BallDraw.java:43: <identifier> expected
              One.size = 10;
                         ^
    BallDraw.java:44: <identifier> expected
               One.x_pos = 50;
                            ^
    BallDraw.java:45: <identifier> expected
               One.y_pos = 50;
                             ^
    Here is my complete new code and I will mark where the errors are:

    Java Code:
    import java.applet.*;
    import java.awt.*;
    
    public class BallDraw extends Applet implements Runnable
    {
    
    	private Image dbImage;
    	private Graphics dbg;
    
    	public void init()
    	{
    		setBackground (Color.blue);
    	}
    
    	public void start ()
    	{
    		Thread th = new Thread (this);
    		th.start ();
    	}
    
    	class Ball
    	{
    		public int size = 10;
    		public int x_pos = 50;
    		public int y_pos = 50;
    		public Ball(){
    			draw();
    		}
    	}
    
    
    	Ball One;
    	One.size = 10; //right here
    	One.x_pos = 50; //and here
    	One.y_pos = 50; //and here
    	void draw();
    
    	public void draw(Graphics g)
    	{
    		g.setColor  (Color.red);
    
    		g.fillOval (x_pos - size, y_pos - size, 2 * size, 2 * size);
    
    
    	}
    
    }

  14. #34
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    O yeah and the draw() method is supposed to be in the ball class.

  15. #35
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default

    What method are the statements with the errors in? It looks like they are orphans.
    Put them in a method.

    What is the following statement supposed to do? Why is it in the program?
    void draw();

  16. #36
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    First of all before I answer those can I ask, is there a method that runs when the program runs? Because I need that then I can fix my program myself I think.

  17. #37
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default

    is there a method that runs when the program runs
    When you use the java command to start execution of your class, the java program looks for and calls the "main" method. Its definition must be:
    public static void main(String[] args)

  18. #38
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    Sweet thanks. I'm gunna close this thread because its getting pretty long, and I'll probably just have a different error if I neeed help still. Thanks for your help.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Methods Please help
    By bdario1 in forum New To Java
    Replies: 33
    Last Post: 03-25-2010, 03:26 AM
  3. Sr. Web Methods Developer Needed
    By pjhong in forum Jobs Offered
    Replies: 1
    Last Post: 08-11-2009, 03:08 PM
  4. Replies: 4
    Last Post: 04-03-2009, 06:36 AM
  5. help needed with methods in subclasses
    By uncopywritable in forum New To Java
    Replies: 4
    Last Post: 08-01-2007, 01:47 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
  •