Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Returning vector

Posted on 2003-11-27
9
Medium Priority
?
279 Views
Last Modified: 2010-03-31
I created the following vector(bookauthorVec) in book class and trying to return in Library class. It compiles, but nothing appears in JList(booklist). I already tested getBookAuthor() with main and it works. When I created vector(bookauthorVec) inside of Library class it worked. If I return string from Book class and store to vecBookAuthor in Library class it also worked.(It appears in JList(booklist).
-----------
Book class
------------
public Vector getBookAuthor(){
      for(int i = 0; i < bhm.size() ; i++){
     bookauthorVec.add(bhm.get(titleVec.elementAt(i).toString()));
    }
return bookauthorVec;
 }
---------------------
Library class
-------------------
Vector vecBookAuthor = new Vector();
Book book = new Book();
vecBookAuthor = book.getBookAuthor() ;

JList bookList = new JList(vecBookAuthor);


Any idea?
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 700 total points
ID: 9834518
firstly you are better off doing:
Book book = new Book();
Vector vecBookAuthor = book.getBookAuthor() ;

If you want to add things later to the list then you should use a Vector to create it and should instead use a DefaultListModel.
0
 
LVL 92

Expert Comment

by:objects
ID: 9834525
Why don't you simply return bhm from getBookAuthor?
0
 

Author Comment

by:dkim18
ID: 9834554
objects;

firstly you are better off doing:
Book book = new Book();
Vector vecBookAuthor = book.getBookAuthor() ;
>>why?

then how do I access Book class' public function from Library class?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 92

Accepted Solution

by:
objects earned 700 total points
ID: 9834941
> Vector vecBookAuthor = new Vector();

here you create a new empty vector

> Book book = new Book();
> vecBookAuthor = book.getBookAuthor() ;

And here you assign the variable a new value.
So the vector you created in the first line is unused.

0
 
LVL 92

Expert Comment

by:objects
ID: 9834946
Where do actually add the elements to bhm?
Unless you add them somehow in the constructor, then it will be empty. Which is why the list is empty.

I would think you should be passing the book details to its constructor.
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 300 total points
ID: 9835103
Might also create a problem when you add some more elements to the bhm Vector and again call the getBookAuthor () method, because then you will end up adding all the previously added elements again. Where are you initializing the bhm and bookauthorVec Vectors, and adding data to the bhm Vector?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9835119
>> bhm.get(titleVec.elementAt(i).toString())

Oh, so there's a titleVec too. By the way, what is the data-type of bhm? Is it a Vector too (initially, it looked like). But Vector does not have a get (String) method if I'm right. It only has a get (int) method.
0
 

Author Comment

by:dkim18
ID: 9842475
thank you for all your help. I stored objects in vector and then put it in JList.
I already submitted this proj and working on next one.
Again, your comment help me a lot.
thanks,
0
 
LVL 92

Expert Comment

by:objects
ID: 9843363
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question