• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with a "common" error.  RSS feed

 
Mike Forieri
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy! As my first post, I decided I would shortly introduce myself. I'm a 15 year old kid who is picking up Java as a hobby after briefly learning VB in school. Anyways, I require some help for a school project in Computer Science. Our goal is to create a 2D game, and I've been working my butt of to do so, but there is this one error getting in my way in 3 of my classes. "The method create is undefined for the type Menu"

This error is going to kill me. I have lots of code, but I think I have to post it all so you understand my context of the problem.

-----
On my next package and class, I run into this error again, this time with less code.



I have two other Packages and Classes with code, but no errors on those, if it is needed, I can post those too. If it makes any difference, I am using Eclipse.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

The first error:
Mike Forieri wrote:"The method create is undefined for the type Menu"

means exactly what it says: there is no method named create() in class java.awt.Menu. What were you trying to accomplish with that statement? See the API documentation of class java.awt.Menu.

The second error:
Mike Forieri wrote:"game cannot be resolved to a variable"

means that there is no variable named game at that point in the program. There's no variable with that name in your class Renderer.

Mike Forieri wrote:"The method render(Graphics) is undefined for the type Menu"

The class java.awt.Menu does not have a method named render which takes a Graphics object as an argument.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Forieri wrote:This error is going to kill me. I have lots of code, but I think I have to post it all so you understand my context of the problem.

First: Welcome to javaRanch, Mike.

Second: Congratulations on supplying us with a well thought-out question. I wish others took as much care as you. +1 for that.

Third: I'm no GUI expert, so I won't even begin to try and help solve your problem, because I might just make it worse.
However, I do have a couple of general suggestions for you:

1. Compile, compile, compile - Every 10 lines you write, and every class and/or method you create - and some might say even more often than that. It may seem like a pain when you're just dying to see some results, but it'll help prevent the sort of problems you're running into now.
Java is a "picky" language (just one thing being that it's case-sensitive), and the compiler is NOT forgiving. Do you think you can write 20 lines without a spelling mistake, or a missing brace, or bracket, or semicolon? I know I can't, and I've been at this lark a long time ... and that's BEFORE you even get into logic errors...

2. StopCoding (←click) - Some of your errors suggest that you're "thinking in Java". For instancee: You know you want to "render" something, but you're not exactly sure how; you want to create a Menu, but you're not exactly sure how ....
Oddly enough, that's no bad thing, because at least you have an idea of WHAT you want to do. My suggestion would be to go one step further and write it all down in English (or your native language) before you write any more code. You might also want to read the WhatNotHow (←click) page for more info.

HIH

Winston

PS: We also ask people to UseCodeTags (←click) when they post code. I've added yours this time; see how much better it looks?

Just remember that when you do: DontWriteLongLines. It screws up the window formatting here. You can probably see that I've broken up your "error indicators" into multi-line comments for just that reason.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: - Every 10 lines you write, and every class and/or method you create - and some might say even more often than that.

Me, for one. I go about 2-3 lines before compiling. VERY rarely would I go more than 5.
 
Mike Forieri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I took into consideration of the "Stop Coding" method, however I'm still struggling a bit. I'm not too sure how to format my Method for Menu.create(); and Menu.render(g);

I am also having errors after making switch(game.state){

I made game a local variable so it reads

Object game;
switch(game.state){ <---- Here it says "state cannot be resolved or is not a field"
}
Menu.render(g); <------ Here I'm not sure how to format creating the method
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Forieri wrote:I made game a local variable so it reads
Object game;
switch(game.state){ <---- Here it says "state cannot be resolved or is not a field"
}
Menu.render(g); <------ Here I'm not sure how to format creating the method

Well, the first error comes from the fact that you've made 'game' an Object. And Object has no field called 'state' (or if it does, you certainly can't "see" it).

I suspect very strongly that game is actually another type altogether (Game?).

As for your Menu.render() line: I think Jesper already explained the problem: java.awt.Menu doesn't have a render() method.

Now, you might want to "render a menu", but you can't simply translate an English requirement directly into Java code - you need to understand how the Menu class works. And the way to do that is to look a the API documentation, or read the tutorials.

I hate to say, but I fear you may be trying something that's beyond your capabilities at the moment. That doesn't mean it always will be, but you really need to understand how Java GUIs work before you start tackling a game.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!