• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.Error  RSS feed

 
Moon Lu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When I run the code, idea throws exception:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
RandomShapeGenerator cannot be resolved to a type
The method draw() is undefined for the type Shape

at Shapes.main(Shapes.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

What's wrong?
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

you should never try to run code with a red mark against it. Those Exceptions occur when IDEs like Eclipse (I think NetBeans, too) are asked to run code with compile‑time errors. You should go back to the code, and find the red marks. If you hover your mouse on the red mark, you should get an explanation of the error and maybe even suggestions how to correct it.
Which package is the random shape generator class.

Di you know you can make that toString method polymorphic? Look!Easy!
But I think your toString method would return sizes, etc. You can do that with super.toString() + ...
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moon Lu wrote:
When I run the code, idea throws exception:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
RandomShapeGenerator cannot be resolved to a type
The method draw() is undefined for the type Shape

at Shapes.main(Shapes.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

What's wrong?


First, read this ... http://www.coderanch.com/how-to/java/FixAllCompilerErrorsBeforeRunningTheApplication

Anyway, the error message is complaining about something named RandomShapeGenerator -- which doesn't exist in the code you posted.

Henry
 
Moon Lu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Moon Lu wrote:
When I run the code, idea throws exception:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
RandomShapeGenerator cannot be resolved to a type
The method draw() is undefined for the type Shape

at Shapes.main(Shapes.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

What's wrong?


First, read this ... http://www.coderanch.com/how-to/java/FixAllCompilerErrorsBeforeRunningTheApplication

Anyway, the error message is complaining about something named RandomShapeGenerator -- which doesn't exist in the code you posted.

Henry


I rewrite code

shows error: Type 'List' doesn't have type parameters
 
Moon Lu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

You should never try to run code with a red mark against it. Those Exceptions occur when IDEs like Eclipse (I think NetBeans, too) are asked to run code with compile‑time errors. You should go back to the code, and find the red marks. If you hover your mouse on the red mark, you should get an explanation of the error and maybe even suggestions how to correct it.
Which package is the random shape generator class.

Di you know you can make that toString method polymorphic? Look!Easy!
But I think your toString method would return sizes, etc. You can do that with super.toString() + ...

Thanks, the error is in row 26, I delete "java.util." shows "Type 'List' doesn't have type parameters"
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two things called List. You want this one and you have probably got this one.
Start by correcting the imports.

Beware: if you write Lis<ctrl‑space> on Eclipse you get a dropdown list of classes beginning with Lis…. If you click the first List which appears or simply push enter, you get the wrong import.
 
Moon Lu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I got it.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!