This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes JAVA Compilation problem.  Problem with importing code using the Get Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JAVA Compilation problem.  Problem with importing code using the Get Method" Watch "JAVA Compilation problem.  Problem with importing code using the Get Method" New topic
Author

JAVA Compilation problem. Problem with importing code using the Get Method

Nathe Chan
Ranch Hand

Joined: Mar 12, 2009
Posts: 33
Hey guys. I'm really stuck on getting stuff from the MovieInfo array and then subsequently importing it into the JListBox. I need some help here. Can you help me?

I have a compilation error. And, this is it.

MovieBuy.java:180: non-static method getMovieTitle() cannot be referenced from a static context
vtMovieTitles.addElement(MovieInfo.getMovieTitle());

My code is as follows.

MOVIEBUY.JAVA





MOVIEINFO.JAVA



If you could help me fix these nightmares to fulfull my dream to come true, that would be so awesome!

For a visual image of the question, it is listed here on SCRIBD

URL:: http://www.scribd.com/doc/13082448/CSIS1275Assign3w2009

Thanks,

Nathe
Lucas Franceschi
Ranch Hand

Joined: Nov 10, 2008
Posts: 106

well
if you change



to



I guess it will work.. the only problem is, I dont know how to explain you why it would work, and if doing this is good practice or not.

anyone help us?

probably this occurs beacuse you're acessing a non-static method in a static context (just what the error says.), but i cant see how it applies here.

sorry for the shallow answer, just thought I could help.


Lucas Franceschi
Software Developer for SGI Sistemas, lukas1596@gmail.com
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39573
    
  27
Do you understand the difference between a static method and a non-static method? If not, this would be a good time to read up on that in your favorite Java tutorial.

Instead of calling "MovieInfo.getMovieTitle()" you need to do "myMovieInfo.getMovieTitle()", where "myMovieInfo" is an object of type MovieInfo.


Ping & DNS - updated with new look and Ping home screen widget
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39573
    
  27
Lucas Franceschi wrote:...I guess it will work....

That will not work. "strMovieTitle" is assigned a value in the MovieInfo constructor - so an object of that class must be created, and it is that object instance that must be used in the call to getMovieTitle.
Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
    
    2
The problem is in this part of the code

MovieInfo as Ulf pointed out will not work. But I would suggest stepping through these few lines and ask yourself what are they doing. Big hint where is the method getMovieStock(i)?
Nathe Chan
Ranch Hand

Joined: Mar 12, 2009
Posts: 33
I tried MyMovieInfo already. It did not work. ugh

- Nathe
Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
    
    2
Try this for that line


That will correct that problem, but you still have several other minor problems. You will need only one for loop, and check out which JBoxes you are putting the inventory into.
Nathe Chan
Ranch Hand

Joined: Mar 12, 2009
Posts: 33
Thanks all for your help!
And, I do still think that Lucas Franceschi has the BEST ANSWER. Good job Lucas.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36566
    
  16
You have already been told what will and won't work. I don't think you will get the solution with "static" in even to compile.
Nathe Chan
Ranch Hand

Joined: Mar 12, 2009
Posts: 33
Hey guys. I'm still brutally stuck.

Here's my code.



Here's what I'm getting in the JList. The first time I click the button, nothing shows up, but when I click the button and then maximize the JApplet screen, then something shows up. That's the weirdest problem I have ever got.

What am I doing wrong here.

My output is the following:

MovieTitles DVD Stock blu Ray Stock
Made of Honor 25 56
Made of Honor 25 56
Made of Honor 25 56
Made of Honor 25 56
Made of Honor 25 56
Made of Honor 25 56
Made of Honor 25 56

Can you help me fix this and explain to me why the computer is doing this to me?

Nathe Chan
Ranch Hand

Joined: Mar 12, 2009
Posts: 33
Okay, I figured it out I used the setListData() method to resolve it. . .
Nathe Chan
Ranch Hand

Joined: Mar 12, 2009
Posts: 33
And, like someone said, "It's not static."

How true!

Thanks to everyone who really helped and CONTRIBUTED.
- Nathe
Lucas Franceschi
Ranch Hand

Joined: Nov 10, 2008
Posts: 106

Nathe Chan wrote:Thanks all for your help!
And, I do still think that Lucas Franceschi has the BEST ANSWER. Good job Lucas.


I cant see in what I've helped.

reading the answers and getting more informed about static. I now see that only putting the "static" keyword in method declaration would not work.

sorry, it was just a guess...

I recommend you to see this, its short, but helped me, for sure will help you.

i'm sorry for the first answer, didn't help at all. =P

well, if it'll help you, I started a thread regarding this, if you read, certainly you'll have a deeper notion about static context:
my thread
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAVA Compilation problem. Problem with importing code using the Get Method
 
Similar Threads
Adding a selected Index from a JList box using the JButton. I'm so confused. :S
Laying out a JPanel
JAVA JList Problem
Difficulty getting a JScrollPane onto a JList box
JAVA JButton Functionality