• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with Array  RSS feed

 
Marshall Lail
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help! I have tried every way to get this to compile. Right now it does not like the "new" statement in invArray[0] = new DVD(0,"Terminator",2,24.95,0); or any other line.

Can someone show me a example of code which contains a working array? Or point out where I have gone astray???

Thanks!!!

 
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
invArray[0] = new DVD(0,"Terminator",2,24.95,0);

invArray is a String array. It holds String objects -- not DVD objects. To hold DVD objects, you need to uses a DVD array.

Henry
 
Marshall Lail
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried that many times and each time I run compile it always stops on the DVD text and states it is not a type. This was why I used a String type. Any example that you can share is appreciated!
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a java .class file named DVD.java?
 
An Sush
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need DVD object to be present in classpath. Check out if you have the class present. If not check out the JARs present in the classpath and check if you able to trace DVD.class. If not, you need to find the class.
Else open the class using some java decompiler and you can see what is the hierarchy of this object and if String is compatile cast
 
Marshall Lail
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Keith Lynn:
Do you have a java .class file named DVD.java?


Keith, No I know I am lost but when Java compiles it gives you the .class extension. Now if you are asking about the class, well yes I have a class but I think it is main. Are you saying the class has to be DVD if I am referencing DVD?

Thanks
 
Marshall Lail
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by An Sush:
You need DVD object to be present in classpath. Check out if you have the class present. If not check out the JARs present in the classpath and check if you able to trace DVD.class. If not, you need to find the class.
Else open the class using some java decompiler and you can see what is the hierarchy of this object and if String is compatible cast


An Sush,

I read your reply 3 times. The first time I felt it would be easier to learn German! I know it is just my ignorance... Since all of my code is in the same directory why would I need a classpath? Now your comment about JARs, I will have to look up what JAR's means. I have not come across this in my class so I am lost here.

What I would learn more from is seeing the examples of what everyone is stating. This way I could tie your words to the example, anyone? Without that I am just

Thanks!
 
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
Basically, everyone is saying that it has nothing to do with arrays. And the problem is either caused by the DVD class, or your compile environment. Please provide exactly....

- The exactly error code that you are receiving while compiling -- along with the command that you used.

- The source code for the DVD class (if it is not too big).


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