[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Question about using JAVA Vector()

Posted on 2004-10-26
6
Medium Priority
?
233 Views
Last Modified: 2010-03-31
My program looks as follow:

class FirstClass extends ...
{
...
...
 Vector v = new Vector();
 for(int i=0; i<5; i++)
 {
   v.add(i, new SecondClass());
  }
 ...
 ...
 for(int j=0; j<v.length; j++)
   v.elementAt(i).print("test");  // I hae problem here
}

class SecondClass extends JComponent
{
 ...
 ...
 public void print(String msg)
 {
   System.out.println(msg);
 }
}

But I get problem as noted above. Why?
0
Comment
Question by:chenwei
[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
  • 4
6 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 120 total points
ID: 12411031
Try casting

    ((SecondClass)v.elementAt(i)).print("test");
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12411035
>>v.elementAt(i).print("test");  // I hae problem here


should that be

v.elementAt(j).print("test");  // I hae problem here

?
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12411042
v.elementAt(i).print("test");  // I hae problem here
should be
((SecondClass) v.elementAt(i)).print("test");  // I hae problem here
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:zzynx
ID: 12411049
elementAt returns an object of type Object.
The class Object doesn't have a print() function.
So you have to cast the Object to a SecondClass object which has the print() function
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12411060
and it should be j indeed
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12411201
Thanks
0

Featured Post

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.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

656 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