Results 1 to 15 of 15
Thread: Cannot instantiate a type
- 07-04-2011, 03:01 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 17
- Rep Power
- 0
Cannot instantiate a type
I'm doing a project with Eclipse and 1 error occurred in a class, I'll report the part of code where is signed:
Nemico[] nemici=new Nemico[numNemici];
for(int e=0;e<numNemici;e++){
nemici[e]=new Nemico(vita,forza,destrezza,costituzione); //here!
}
the variable "numNemici" is istantiated in the costructor of the class (Arena in the specified case).
"vita","forza","destrezza","costituzione" are private fields of the class (Arena).
"Nemico" is the problem, but it's a costructor defined in the class Nemico:
public Nemico(double vita,double forza,double destrezza,double costituzione){
x=(int)Math.random()*100 //x e y are protected fields of the class Nemico
y=(int)Math.random()*100
this.vita=vita;
this.forza=forza;
this.destrezza=destrezza;
this.costituzione=costituzione;
//.... (other things XD)
}
So..where is the problem?Any idea?
Eclipse just segnalized the problem, but don't suggest a solution.
- 07-04-2011, 04:03 PM #2
Can you compile it and have the compiler tell you where the error is?So..where is the problem?
- 07-04-2011, 04:06 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 17
- Rep Power
- 0
the error is "Cannot instantiate the type Nemico", at the line where I wrote "here!" as a comment.But I don't undestand why Nemico cannot be instantiated.ç_ç
- 07-04-2011, 04:13 PM #4
Can you use the javac command and get an error from the compiler
or won't the IDE allow you to compile the program?
- 07-04-2011, 05:00 PM #5
Member
- Join Date
- Jul 2011
- Posts
- 17
- Rep Power
- 0
Sorry, I don't know Eclipse very well so I don't know how to compile a file with IDE..but I've copy the file in JEdit: the compiler as signed only the "normal" errors as "cannot find symbol" (normal because I haven't copy all the other classes in 1 folder, just the class Arena where the problem occurred)..
- 07-04-2011, 05:03 PM #6
Hard to suggest anything without the full text of the error message.
- 07-04-2011, 05:42 PM #7
Member
- Join Date
- Jul 2011
- Posts
- 17
- Rep Power
- 0
I've read that to compile with IDE you can check "Build Automatically", the option is set on and the text of the error is "Cannot instantiate the type Nemico"..there aren't other messages.
Clicking on "Quick fix" there arent'n suggestions to solve the problem.@_@
- 07-04-2011, 06:10 PM #8
The IDE is hiding the compiler error. Try using the javac command to compile the program.
- 07-04-2011, 06:33 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Switch off the Build Automatically option and do it manually via the Build button.
I think (though it's been a while since I used it) that should give you a proper compilation.
- 07-04-2011, 06:55 PM #10
Member
- Join Date
- Jul 2011
- Posts
- 17
- Rep Power
- 0
- 07-04-2011, 09:27 PM #11
Member
- Join Date
- Jul 2011
- Posts
- 17
- Rep Power
- 0
maybe the problem is that Arena is'nt the main class and have not the main method?
- 07-04-2011, 09:32 PM #12
No, the compiler doesn't check for that.
- 07-04-2011, 11:05 PM #13
Member
- Join Date
- Jul 2011
- Posts
- 17
- Rep Power
- 0
mmh the problem is solved,was as well as i think.o.O Thanks
- 07-05-2011, 09:34 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
- 07-06-2011, 05:03 PM #15
Member
- Join Date
- Jul 2011
- Posts
- 17
- Rep Power
- 0
Similar Threads
-
Can I exclude a file from being instantiated by JUnit?
By nolsen01 in forum NetBeansReplies: 0Last Post: 06-21-2011, 02:02 AM -
Internal error-- Cannot Instantiate Font Class??
By MatthewC.Dowell in forum New To JavaReplies: 1Last Post: 05-29-2011, 07:00 PM -
help instantiate a java class that extend applet
By geosa in forum Java AppletsReplies: 0Last Post: 12-04-2010, 09:14 AM -
[SOLVED] Unable to instantiate class?
By xcallmejudasx in forum New To JavaReplies: 1Last Post: 11-03-2008, 04:03 PM -
How to instantiate Class, into jsp, java script
By silvia in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-07-2007, 05:45 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks