HELP?! a class that implements ..... : java.util.Vector
My instructions say this:
In the constructor, create the collection object (Since java.util.List is an interface, you will need to instantiate a class that implements this interface: java.util.Vector or java.util.LinkedList or java.util.ArrayList).
I know, this IS a homework assignment - I am not sure how to go about this. I DO have code so far up to this point, can anyone help?
import dLibrary.*;
import java.awt.Color;
* @author Rob
* @version 8/18/03
public class PhrasesII extends A3ButtonHandler
private A3ButtonWindow win;
private ATextField stringAcceptor;
private ALabel listOstrings;
private ALabel inputString;
private ALabel status;
private java.awt.List display;
private java.util.List collection;
public PhrasesII()
win = new A3ButtonWindow(this);
stringAcceptor= new ATextField (50,420,200,25);
stringAcceptor.place(win);
listOstrings = new ALabel(100, 10, 100, 380);
listOstrings.setFontSize(10);
listOstrings.setText("List of Strings:");
listOstrings.place(win);
inputString = new ALabel(50,400,200,25);
inputString.setFontSize(10);
inputString.setText("Input String:");
inputString.place(win);
display = new java.awt.List();
display.setLocation(200, 100);
display.setSize(200, 250);
display.setBackground(Color.lightGray);
win.add(display, 0);
win.setLeftText("Save");
win.setMidText("Display");
win.setRightText("Discard");
win.repaint();
public void leftAction()
public void midAction()
public void rightAction()
I am getting a " can't resolve symbol" when I do thisYou have to either import java.util.ArrayList or specify it fully, e.g., "new java.util.ArrayList()".
Is that the line that is causing you problems? The error message should give the line number.
my instructions also say I have to use "interface
java.util.List when declaring your reference" so I am
confused about using "= new ArrayList();"What they're saying is that you want code like this:
private java.util.List frogs; // this is the reference declaration
//... later on...
frogs = new java.util.ArrayList(); // this isn't a declarationWhat this means is that when you declare a field or variable, you should declare its type to be an interface.
But when you actually instantiate a value for that variable, then you should use a concrete class that implements that interface. (You have to; interfaces can't be instantiated.)
This is good programming style for reasons I don't have the space to explain here.
Similar Messages
-
hi to all,
i am using a session less bean A to querry a Entity Bean B , which inturns calls another EntityBean C ,
finally a ' find' method is invoked on the EntityBean C, In this a vector is created which holds 3 different vectors at different indexes, now the problem i am facing is that when Enity Bean B is returning the final vector to the A , it's firing out a errors that :-
TRANSACTION COULD NOT BE COMPLETED: RemoteException occurred in server thread;
ested exception is:
java.rmi.RemoteException: null; nested exception is:
java.rmi.ServerException: RemoteException occurred in server thread; ne
ted exception is:
java.rmi.RemoteException: null; nested exception is:
java.io.NotSerializableException: java.util.Vector$1
java.rmi.ServerException: RemoteException occurred in server thread; nested exc
ption is:
java.rmi.RemoteException: null; nested exception is:
java.rmi.ServerException: RemoteException occurred in server thread; ne
ted exception is:
java.rmi.RemoteException: null; nested exception is:
java.io.NotSerializableException: java.util.Vector$1
java.rmi.RemoteException: null; nested exception is:
java.rmi.ServerException: RemoteException occurred in server thread; ne
ted exception is:
java.rmi.RemoteException: null; nested exception is:
java.io.NotSerializableException: java.util.Vector$1
java.rmi.ServerException: RemoteException occurred in server thread; nested exc
ption is:
java.rmi.RemoteException: null; nested exception is:
java.io.NotSerializableException: java.util.Vector$1
java.rmi.RemoteException: null; nested exception is:
java.io.NotSerializableException: java.util.Vector$1
java.io.NotSerializableException: java.util.Vector$1
<<no stack trace available>>
ur any help would be highly appricated to solve out this prob.
If i try to iterate through this vector it's gives IOR:0232003x343242344asdsd................................................blabla....................
thanxs in adavance
DeepakHi I think you are using the method elements() in a remote method.
This method can't be Serializable!! Because it returns an Interface. Interfaces are never Serializable.
Regards,
Peter -
Java.io.NotSerializableException: java.util.Vector$1
I am using Java 2 in the API it says that the Vector implements Serializable but I am getting an exception java.io.NotSerializableException: java.util.Vector$1 I don't know why please help.
Thank you
palanisrAlthough Vectors are Serializable that doesn't mean that the contents of a Vector are necessarily Serializable. What are the contents of your Vector? Are they objects of a Serializable class? If not that is your problem. The attached sample code demonstrates the problem of serializing a Vector that contains non-serializable data. If you make the Employee class Serializable the code works.
import java.util.*;
import java.io.*;
public class Serialize
public static void main(String args[])
ObjectOutputStream oos = null;
FileOutputStream fos = null;
Vector v = new Vector();
v.add(new Employee("Smith","John"));
v.add(new Employee("Jones","Albert"));
try
fos = new FileOutputStream("vector.ser");
oos = new ObjectOutputStream(fos);
oos.writeObject(v);
catch(FileNotFoundException fnfe)
fnfe.printStackTrace();
catch(IOException ioe)
ioe.printStackTrace();
finally
try
if (oos != null)
oos.close();
catch(IOException ioe)
try
if (fos != null)
fos.close();
catch(IOException ioe)
class Employee //implements Serializable
private String lastName;
private String firstName;
public Employee(String lastName, String firstName)
this.lastName = lastName;
this.firstName = firstName;
} -
Java.util.vector package
What is in the java.util.vector package and why is it used (imported)?
ThanksCan you tell me what the Vector class is use for?First of all, forget about Vector. When anyone mentions Vector, your response should be "You're still using Vector? Are you still in 1.1?"
Use ArrayList. It's basically the same but better. It's a List. You know what a List is right? It's a group or ordered items that can contain duplicates. An ArrayList is basically a List that is backed by an array. The greate thing about it is that it automatically makes itself bigger as needed and implements probably the most commonly supported Java type: Collection. -
Reflect the class that implements Runnable
Hi,
I am implementing the reflection of the class that implements Runnable. In order to start a new thread I am trying to invoke "start()" method ( which is obviously not defined my class ) and I therefore I am getting "java.lang.NoSuchMethodException".
I am wondering is it possible at all to start a new thread on a reflected class?
thanks in advance.
{ Class refClass = Class.forName(className);
String methodName = "start";
Class[] types = new Class[1];
types[0] = Class.forName("java.util.HashMap");
Constructor cons = refClass.getConstructor(types);
Object[] params = new Object[5];
params[0] = new HashMap();
Method libMethod = refClass.getMethod(methodName, null);
libMethod.invoke(objType, null); }Well, if we knew what it meant to "start a thread on a class" we could probably figure out how to "start a thread on a reflected class". If we knew what a "reflected class" was, that is.
In other words, it would help if you rephrased your question using standard terminology (and also explained why you want to do whatever it is you want to do).
But let's guess for now: If you have an object which implements Runnable then you start a thread to run that object like this:
Runnable r = // some object which implements Runnable
new Thread(r).start();Not what you wanted? Go ahead and clarify then. -
Hi everybody!
Does anyone know how to use unsupported
J2SE classes in a PersonalJava application?
I would like to use for example the class
java.util.Vector in my PersonalJava application,
but I have not succeeded to do that.
I would be grateful if someone could give
me advice.
-Toni
[email protected]To use vector you have to be careful only to use the java 1.1.x functionality, ie don't use any of the functions that it inherits from Collections, as they were Java 1.2.
In reality this means that you need to use addElement instead of add etc.
Hope this helps
Peter -
Java.util.vector value to String
Hi
I am trying to use some API calls for securecomputing. One of the value when i print using API, i get the result as
java.util.Vector$1@93d6bc
How do i convert this value into readable string format.
Thanks for any help
JosephEven after adding toString() it still returns the
same value.
System.out.println("Role " +
(user.getValue(User.IDS_ROLE)).toString());
Returns "Role java.util.Vector$1@93d6bc"
User.IDS_ROLE is an int
Thanks for the repliesWe didn't mean for you to explicitly call toString(), we meant for you to implement it. What kind of class does user.getValue(int) return? Surely it's not a java.util.Vector, but something else - what it is returning looks confusing (java.util.Vector$1...) -
Problems with protected access in java.util.vector
Hi,
basically i'm trying to use the method removeRange(int,int) of class Vector from the java API.
I keep getting the following compiler message:
removeRange(int,int) has protected access in java.util.vector.
This seems rather vague, and i don't know quite what to do?
Thanks in advanceremoveRange(int,int) has protected access in java.util.vector.
This seems rather vague, and i don't know quite what to do?As error messages go, that's pretty clear: method removeRange is a protected method and you can only call public ones of Vector, right? You can always combine subList and clear:
vec.subList(fromIndex, toIndex).claer(); -
Hi everybody:
I created a Mobile service component and a Data Structure with 3 attributes. I created and instantiated the collection and showed all objects in a table but I´m getting the following error:java.lang.NoSuchMethodException: java.util.Vector.isX() where X is the name of the each attribute I defined. so I´m getting this error twice for each attribute.
Complete stack:
java.lang.NoSuchMethodException: java.util.Vector.isX()
at java.lang.Class.getMethod(Class.java:1581)
at com.sap.tc.mobile.wdlite.progmodel.core.context.JavaBeanCMIModel.invokeMethod(JavaBeanCMIModel.java:366)
at com.sap.tc.mobile.wdlite.progmodel.core.context.JavaBeanCMIModel.invokeGetMethod(JavaBeanCMIModel.java:279)
at com.sap.tc.mobile.wdlite.progmodel.core.context.JavaBeanCMIModel.getAttributeValue(JavaBeanCMIModel.java:81)
at com.sap.tc.mobile.wdlite.progmodel.core.context.NodeElement.getAttributeValue(NodeElement.java:104)
at com.sap.tc.mobile.wdlite.progmodel.core.context.NodeElement.getAttributeValue(NodeElement.java:85)
at com.sap.tc.mobile.wdlite.progmodel.core.context.NodeElementWrapper.getAttributeValue(NodeElementWrapper.java:26)
at com.sap.tc.mobile.wdlite.progmodel.core.context.ContextNode.getAttributeValue(ContextNode.java:578)
at com.sap.tc.mobile.wdlite.progmodel.core.context.ContextNode.getAttributeValue(ContextNode.java:569)
at com.sap.tc.mobile.wdlite.progmodel.core.context.ContextNodeMapped.getAttributeValue(ContextNodeMapped.java:134)
at com.sap.tc.mobile.wdlite.progmodel.core.viewelement.Property.listenContextNodeCursorChanged(Property.java:173)
at com.sap.tc.mobile.wdlite.progmodel.core.context.ContextNode.addContextNodeElementListener(ContextNode.java:616)
at com.sap.tc.mobile.wdlite.progmodel.core.viewelement.Property.setBinding(Property.java:73)
at com.sap.tc.mobile.wdlite.progmodel.core.viewelement.Property.setBinding(Property.java:57)
at com.xioma.demo.testeui0001.comp1.Comp1ViewView.(Comp1ViewView.java:615)
at com.xioma.demo.testeui0001.comp1.Comp1ViewView.getInstance0(Comp1ViewView.java:31)
at com.xioma.demo.testeui0001.comp1.Comp1ViewView.getInstance(Comp1ViewView.java:45)
at com.xioma.demo.testeui0001.comp1.Comp1WindowWindow.getDefaultView(Comp1WindowWindow.java:38)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.navigate(Application.java:477)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.enter(Application.java:243)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.setCurrent(Application.java:119)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.launch(Application.java:143)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.launch(Application.java:175)
at com.sap.tc.mobile.wdlite.progmodel.core.WDLite.launchApplication(WDLite.java:387)
at com.sap.tc.mobile.wdlite.container.ContainerApp.startApp(ContainerApp.java:155)
at com.sap.tc.mobile.wdlite.container.AppMenuView.onActionLaunchApp(AppMenuView.java:327)
at com.sap.tc.mobile.wdlite.container.AppMenuView.invokeEventHandler(AppMenuView.java:370)
at com.sap.tc.mobile.wdlite.progmodel.core.AbstractViewElement.doHandleEvent(AbstractViewElement.java:207)
at com.sap.tc.mobile.wdlite.renderer.api.UIElement.doHandleEvent(UIElement.java:399)
at com.sap.tc.mobile.wdlite.renderer.api.UIImageButton.mouseReleased(UIImageButton.java:148)
at com.sap.tc.mobile.wdlite.renderer.api.UIElement.dispatchMouseReleasedWidgetEvent(UIElement.java:442)
at com.sap.tc.mobile.wdlite.renderer.api.UIElement$1.mouseReleased(UIElement.java:485)
at com.sap.tc.mobile.wdlite.renderer.swt.MouseEventDispatcher.mouseUp(SWTControl.java:362)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:137)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
at com.sap.tc.mobile.wdlite.renderer.swt.container.WorkingArea.refresh(WorkingArea.java:175)
at com.sap.tc.mobile.wdlite.renderer.api.RenderingManager.refresh(RenderingManager.java:233)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.refresh(Application.java:250)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.navigate(Application.java:503)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.enter(Application.java:243)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.setCurrent(Application.java:119)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.launch(Application.java:143)
at com.sap.tc.mobile.wdlite.progmodel.core.Application.launch(Application.java:175)
at com.sap.tc.mobile.wdlite.progmodel.core.WDLite.launchApplication(WDLite.java:387)
at com.sap.tc.mobile.wdlite.framework.Start.runOnContext(Start.java:585)
at com.sap.tc.mobile.wdlite.framework.Start.startApplication(Start.java:609)
at com.sap.tc.mobile.wdlite.framework.Start.startContainer(Start.java:646)
at com.sap.tc.mobile.cfs.framework.spi.FrameworkManager.startContainer(FrameworkManager.java:259)
at com.sap.tc.mobile.cfs.init.FrameworkInitializer.init(FrameworkInitializer.java:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sap.tc.mobile.cfs.startup.pda.Startup.main(Unknown Source)
The errors are throw when the application starts, the custom code works ok.
Any idea?
Thanks a lot for your time on this thread.
Rocío.Ho Rocio,
The creme JVM is compatible with JDK 1.3.Please make sure that the API you are using is available in 1.3 API set.
Best Regards,
Amit -
After using jexegen from microsoft to make EXE. I receive this error when i execute the my EXE :
java.lang.NoSuchMethodError: java/util/Vector method revove...
Any body know why?
If i execute from JBuilder i have no problem!hi, i don't have much experience with M$ java products, but as far as i remember, M$ java stopped developping since jdk 1.1.4 (or 1.1.7).
maybe that's the reason for throwing this exception. if you want to "exe" your class-file, try JToExe.
greetzzz
chris -
By benefit I mean does it reduce compile time or have some other beneficial side effect to import only those classes you're using in a class rather than importing the package they reside in.
For example:
// this?
import java.util.Vector;
// or this..
import java.util.*;
class Test
Vector v;
}Question is strictly academic...I'm just curious.I like Dr. clap's answer. Also, though you can
consider code readability. Obviously importing a
whole package doesn't give you an idea of what classes
are being used. "I", personally, have only seen exact
class imports done when learning something new. This
is basically just for clarity, and not speed as Dr.
Clap pointed out.That's probably a good thing to do for examples, but I can't see why you would want to know what individual classes are being used otherwise.
From a programming standpoint if you're going to build a complex dialog you don't want 500 import statements. If you know you're going to be using lots of classes from an individual package might as well import the whole thing. -
Modifying a Class that implements Serializable
I have a class LDAPUser
import java.io.*;
public class LDAPUser implements java.io.Serializable{
private java.lang.String name;
private java.lang.String userID;
private java.lang.String associateNumber;
public LDAPUser() {
super();
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof LDAPUser))
return false;
return (((LDAPUser)o).getAssociateNumber().equals(this.getAssociateNumber()));
public java.lang.String getAssociateNumber() {
if(associateNumber == null){
return getUserID();
return associateNumber;
public java.lang.String getName() {
return name;
public java.lang.String getUserID() {
return userID;
public void setAssociateNumber(java.lang.String newAssociateNumber) {
associateNumber = newAssociateNumber;
public void setName(java.lang.String newName) {
name = newName;
public void setUserID(java.lang.String newUserID) {
userID = newUserID;
It works fine.
I needed to add functionality to it. These were the modifications.
private java.lang.String distinguishedName;
private boolean validUser;
public java.lang.String getDistinguishedName() {
return distinguishedName;
public boolean isValidUser() {
return validUser;
public void setDistinguishedName(java.lang.String newDistinguishedName) {
distinguishedName = newDistinguishedName;
public void setValidUser(boolean newValidUser) {
validUser = newValidUser;
I am using visual age for java and in the Test environment the changes work fine.
When I promote the changes to our application server (websphere) the changes are not there. I get a method not found error and though trial and error have identified that the server is not actually using the class from the jar. I have removed any other occurences of the class from the server.
My question is if I change a Serializable class how do I make those changes take affect (thorough better coding) and for right now, where is this "old instance" of my class coming from and how do I get rid of it.
Thanks in Advance,
Jason GrieveIf the server is running than the class might be already loaded through the class loader, so it wont be load again.
this unless you use hot deployment, which you have to figure how it is being handled in your srver.
Doron -
Serializing a class that implements the Singleton pattern
Hello,
I am relatively new to Java and especially to serialization so the answer to this question might be obvious, but I could not make it work event though I have read the documentation and the article "Using XML Encoder" that was linked from the documentation.
I have a class that implements the singleton pattern. It's definition is as follows:
public class JCOption implements Serializable {
private int x = 1;
private static JCOption option = new JCOption();
private JCOption() {}
public static JCOption getOption() { return option; }
public int getX() { return x; }
public void setX(int x) { this.x = x; }
public static void main(String args[]) throws IOException {
JCOption opt = JCOption.getOption();
opt.setX(10);
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Test.xml")));
encoder.setPersistenceDelegate(opt.getClass(), new JCOptionPersistenceDelegate());
encoder.writeObject(opt);
encoder.close();
}Since this class does not fully comply to the JavaBeans conventions by not having a public no-argument constructor, I have create a class JCOptionPersistenceDelegate that extends the PersistenceDelegate. The implementation of the instantiate method is as follows:
protected Expression instantiate(Object oldInstance, Encoder out) {
Expression expression = new Expression(oldInstance, oldInstance.getClass(), "getOption", new Object[]{});
return expression;
}The problem is that the resulting XML file only contains the following lines:
<java version="1.5.0_06" class="java.beans.XMLDecoder">
<object class="JCOption" property="option"/>
</java> so there is no trace of the property x.
Thank you in advance for your answers.How about this:
import java.beans.DefaultPersistenceDelegate;
import java.beans.Encoder;
import java.beans.Expression;
import java.beans.Statement;
import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class JCOption {
private int x = 1;
private static JCOption option = new JCOption();
private JCOption() {}
public static JCOption getOption() { return option; }
public int getX() { return x; }
public void setX(int x) { this.x = x; }
public static void main(String args[]) throws IOException {
JCOption opt = JCOption.getOption();
opt.setX(10);
ByteArrayOutputStream os = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder( os );
encoder.setPersistenceDelegate( opt.getClass(), new JCOptionPersistenceDelegate() );
encoder.writeObject(opt);
encoder.close();
System.out.println( os.toString() );
class JCOptionPersistenceDelegate extends DefaultPersistenceDelegate {
protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(
oldInstance,
oldInstance.getClass(),
"getOption",
new Object[]{} );
protected void initialize( Class<?> type, Object oldInstance, Object newInstance, Encoder out ) {
super.initialize( type, oldInstance, newInstance, out );
JCOption q = (JCOption)oldInstance;
out.writeStatement( new Statement( oldInstance, "setX", new Object[] { q.getX() } ) );
} Output:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_06" class="java.beans.XMLDecoder">
<object class="JCOption" property="option">
<void property="x">
<int>10</int>
</void>
</object>
</java> -
Transform a class that implements JPanel into a bean.
I'd to create a bean, from a class that implements JPanel, that in fact is a custom component.
How can I create a bean?
I have absolutely no idea about beans.
What can make beans for me?
I know a lot about the theory of ejb, is this what I need?
I'm quite confused, please make me see the light!!!!!
Thanks.Hi Daniel!
To answer your question short as possible:
Java -Beans are reusable code - components,
similar to VB Active -X components,
which you can use when developing your own
applications.
Beans can have a graphic user interface, so you
can use builder tools like JBuilder or Beanbox
to show them graphically in a designer.
You can modify them about their properties,
mostly shown in a special property window of a
builder tool.
It's really not very hard to create your own beans,
the only thing you have to do is to pack all the
classes which make the bean into a jar file.
Then you can import the bean with the builder
and it will be shown.
The jar manifest file needs to look like for example:
Manifest-Version: 1.0
Name: BeanClock.class
Java-Bean: True
All the properties are implemented by public property-get
and property-set methods, in order to show them in the property window.
Java is doing that by introspection.
Hope, this makes it a little bit clearer for you! -
Java.util.Vector
Hello,
I keep getting this error message, although things used to work fine before.
Error : Method toArray(SecurityConstraint[]) not found in class java.util.Vector.
PolicyEnforcer.java line 36
Snippet of code
import java.util.*;
//blabla
Vector constraints = inv.getConstraints();
SecurityConstraint [] constr = (SecurityConstraint [])constraints.toArray(new SecurityConstraint[0]);Any ideas what could be wrong??
thanxHi,
Why not try this:
SecurityConstraint[] constr = (SecurityConstraint[])
constraints.toArray( new SecurityConstraint[constraints.size()] );HTH
~Bill
Maybe you are looking for
-
User can't print from Reader, tried multiple troubleshooting steps
Working with a client who can no longer print from Reader (v11.0.10). Windows 7 Pro x86 machine. Tried printing after each of the following steps: Rebooted PC Restarted Print Spooler service Uninstalled/Reinstalled Reader v11 (from fresh download) S
-
WRT54GS v6 - Port Forwarding Field Colors (Yellow vs Green)?
WRT54GS v6, Firmware 1.52.0 Can anyone explain the color coding for the text field backgrounds under the "Port Forwarding" section? I have severally seemingly normal port forwarding entries with green backgrounds, and then one entry whose text fields
-
Changing Songs in the iTunes Store
Hello, When I am playing a song from a list in the iTunes store, and I use the arrow key to play the next song, the song stops playing entirely. Is this a new feature in iTunes 9, or is this just my computer having problems with the program? Thanks f
-
hi friends have to do debug , In t.code AS91 for one asset class i enter some values and goes for TAKE OVER VALUES iam unable to enter the cumilited acquistion values or change these fields are only in display mode.... similarly if i go for another a
-
Can I use apple TV to stream music to an audio receiver?
Can I use apple TV to stream music to an audio receiver?