# Problem With Quicksorting a Vector

Hi there!
I tried to write an extended Vector which can perform a quicksort of itself.
Unfortunately, after the quicksort, everything int his Vector seems "damaged" - although I get the right Strings out of it, the don't seem to be internally right. ANyway, I'll post my code here and hope anyone can tell me what is wrong with it ;-)
public class SortingVector extends java.util.Vector {
public SortingVector() {
super();
public SortingVector(int i, int j) {
super(i, j);
public void sortStrings() {
quickSortStrings(0, this.size() - 1);
private void quickSortStrings(int l, int r) {
if (l < r) {
int r2 = partitionStrings(l, r);
quickSortStrings(l, r2);
quickSortStrings(r2 + 1, r);
private void exchange(int m, int n) {
Object o1 = this.elementAt(m);
this.set(m, this.elementAt(n));
this.set(n, o1);
private int partitionStrings(int m, int n) {
String x = ((String) this.elementAt(m)).toLowerCase(); // Pivot-Element
int j = n + 1;
int i = m - 1;
while (true) {
j--;
while (checklarger(j, x)) {
j--;
i++;
while (checksmaller(i, x)) {
i++;
if (i < j)
exchange(i, j);
else
return j;
private boolean checklarger(int j, String x) {
int count = 0;
String element = ((String) this.elementAt(j)).toLowerCase();
while ((element.charAt(count) == x.charAt(count))
&& (count < element.length() - 1)
&& (count < x.length() - 1)) {
count++;
if (element.charAt(count) > x.charAt(count)) {
return true;
return false;
private boolean checksmaller(int j, String x) {
int count = 0;
String element = ((String) this.elementAt(j)).toLowerCase();
while ((element.charAt(count) == x.charAt(count))
&& (count < element.length() - 1)
&& (count < x.length() - 1)) {
count++;
if (element.charAt(count) < x.charAt(count)) {
return true;
return false;

Unfortunately, after the quicksort, everything int his
Vector seems "damaged" - although I get the right
Strings out of it, the don't seem to be internally
right.I also think you should use the built-in sort but what do you mean by "damaged"?

### Similar Messages

• Problem with filling up vector

Hello,
i'm having a problem with the following code; when i try to fill up the vector, it overwrites the previous values with the new, so the when i add the second item, the first item becomes the second too. So when i return the vector, all values are similar (the last).
public Vector getClients(){
Database singleton = Database.getDatabase();
User user=new User();
Vector clients = new Vector();
try{
singleton.openConnection();
ResultSet rs = singleton.getResultSet("SELECT * FROM tblClients");
while(rs.next()){
user.setNaam(rs.getString("naam"));
user.setVoornaam(rs.getString("voornaam"));
user.setNickname(rs.getString("nickname"));
user.setEmail(rs.getString("email"));
user.setPaswoord(rs.getString("paswoord"));
System.out.print("user added:" + user.getNickname() + "\n" );
System.out.println(user);
singleton.closeConnection();
}catch(SQLException sqle){
sqle.getMessage();
sqle.printStackTrace();
System.out.print(clients.size() + " users added\n");
return clients;
}

You are always adding the same user-Object to the Vector.
You should put the command
user=new User();inside the while-loop to have different objects for different users.

• Type Mapping Problem with java.util.Vector in Axis

Hi,buddies,I want to use the Vector class as the return type of my service, but it seems that there isn't a built-in Ser/Deser factory for Vector, is it?So i think we need to provide our own Ser/Derser. and this is a very common problem,and i wonder how to write my own Ser/Derser, please give me some suggestion,thx!
Best Regards:)

Hi,I checked out the src of Axis 1.2, I found there is a org.apache.axis.encoding.ser.VectorSerializerFactory class and an according org.apache.axis.encoding.ser.VectorDeserializerFactory class.so in the deploy.wsdd i use them as the ser/deser factories in the TypeMapping part inside the service tag.everything goes well and i got no problem deploying the service to axis.But the problem is that when i try to invoke the service and get a vector as return(Suppose the components in the vector is instances of Movie class), the following error occured:
org.xml.sax.SAXException: No deserializer for {urn:movies}Movie
But it is a little bit confusing,for I declared the ser/deser factories for the bean class Movie(with built-in ser/deser factories of axis),and everything was going fine when i deployed the service to axis.So should i still use the TypeMappingRegistry or there are something i just missed.Please give me some suggestion,thx :)
Best Regards:)

• Problem with TreeMap and Vector

Hello,
this is the problem I have:
I declare a Vector like this:
Vector<String> theVector = new Vector<String>();
I put the String needed into the Vector:
In the other hand I had created a TreeMap like this:
private TreeMap<Integer, Vector<String>> theTreeMap;
I now when I try to put the Key and the Element like this my program crash:
theTreeMap.put(1096,theVector);
I think I don't put the data on the good way in the TreeMap...
Any Idea? Thank you very much

In the other hand I had created a TreeMap like this:
private TreeMap<Integer, Vector<String>> theTreeMap;
I now when I try to put the Key and the Element like
this my program crash:
theTreeMap.put(1096,theVector);What do you mean?

• Problem with unchecked/unsafe Vector use

i want to use
public void addPart( Part part )
{ parts.addElement(part); }but i get a
"warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector"
plz tell me wtf that means
and how i get around it

You create a Vector-object without specifiying the type of data it will hold. So somewhere in your code there is the lineVector parts=new Vector();It was done this way until Generics where introduced in Java1.5.
Now with Java1.5 you can (should ?) also state the tyle of elements can store:Vector parts<Part>=new Vector();Now (Java1.5) every call to parts.addElement(type data) expects data to be an Object of type Part, while in the old days (Java1.4) every data of type Object was okay.
So what to do about the warning..
If you don't want to use that new features of Generics, you can either just ignore the warning, because it will not stop the compiler. But if you have a lot of this type of code, you can call javac with the commandline javac -source 1.4 mypackage.MyClass.javaThen the compiler will not issue the warning any more.

• Problem with two dimensional Vector

It is better to use one dimensional array stored in Vector
or use Vector stored in Vector?

nwoedf wrote:
It is better to use one dimensional array stored in Vector
or use Vector stored in Vector?It's better not to use Vector at all, but rather to use a class from Collections such as ArrayList.
As to the question of what to nest in what, I think that this depends on what you are doing with this data structure, how you're using it. For instance in many situations it's often better to nest a non-array/collection object in an arraylist rather than an array or another collection.

I have a Quicksort method that keeps running into a Stack OverFlow error when it attempts to partition.
Here are my methods:
public static void quickSort(int[] a){
int from = 0;
int to = a.length - 1;
sort(a, from, to);
private static int partition(int[] a, int from, int to){
int pivot = a[from];
int i = from - 1;
int j = to + 1;
while (i < j){
i++; while (a[i] < pivot) i++;
j--; while (a[j] > pivot) j--;
if (i < j) swap(a, i, j);
return j;
private static void sort(int[] a, int from, int to){
if (from >= to) return;
int p = partition(a, from, to); // eclipse tells me my error is here.
sort(a, from, p);
sort(a, p + 1, to); // I also have an error here.
}Eclipse points to the sort method as the source of my error, which itself points to my attempting to partition the sucker, so I don't know what's up. It's probably something stupid, but I'm lost, so any help is appreciated.

private static void swap(int[] a, int i, int j){
int temp = a;
a[i] = a[j];
a[j] = temp;
}The quicksort method works until the array size is greater than 9723. That's when I get my overflow error.

• Problems with inserting elements into vectors

Hi,
I have a problem with the setElementAt() method for vectors.
I want to initialise a vector that is same size as a previous vector declared in my program and insert float 0.0 in all the positions.
The code below is a for loop to do just this where count is the size of the previous vector.
for(int i=0;i<count; i++)
vLargest.setElementAt(zero,i);
}i have declared zero as a float
float zero = 0.0f;
the error that i'm getting is that it that the vector cannot be applied to a float.
Can anybody tell me what i'm doing wrong?
Thanks

Yes you need to store Objects in your Vector not primitives.
float is not an Object it is a primitive. But Float is an object.

• Problem with String in a Vector

I'm making a small hangman game. And I got a problem with putting words in a Vector... This is the code... Can someone tell me what I'm doing wrong?
// First I define it.
Vector Words;
//  Then add the words
Vector Words = new Vector();
// When I try to get a string from the Vector I use this.
// The program compiles but when I try to run it I get NullPointerExeption here
W = (String) Words.elementAt(0);

Not sure since I cant see all of your code but looks like this might be your problem:
// First I define it.
Vector Words; //<-- here you define a Vector named Words that is null
// Then add the words
Vector Words = new Vector(); //<-- here you define another vector named Words that holds a reference to a new Vector. This is a different reference than the one created above so you should probably remove the "Vector" part from the beginning of this line. Is this a local variable to a method and the one before is a global variable?
//Here you probably access the locally created Words vector which is initialized
// When I try to get a string from the Vector I use this.
// The program compiles but when I try to run it I get NullPointerExeption here
W = (String) Words.elementAt(0); //<--and here my guess is that this statement is inside another method than the one with the local Words vector defined. Thus this one accesses the global Words Vector that is never initalized and is Null. And that gives you the NullPointerException.
So try changing the statement
Vector Words = new Vector();
to
Words = new Vector();
or just remove it totally and move the Vector creation to the place where you introduce the global variable.
Of course I might be totally wrong since I cant see all of your code but that is my guess.
Hope it helps,
-teka

• Strange Problem with a Vector wraped inside a Hashtable

Hi all ,
I'm having a strange problem with a Vector wraped within a Hashtable inherited Class.
My goal is to keep the order of the elements of the Hashtable so what I did was to extend Hashtable and wrap a Vector Inside of it.
Here is what it looks like :
package somepackage.util;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
public class OrderedHashTable extends Hashtable {
private Vector index;
/** Creates a new instance of OrderedHashTable */
public OrderedHashTable() {
this.index = new Vector();
//adds a key pair value to the HashTable and adds the key at the end of the index Vector
public synchronized Object put(Object key,Object value){
Object obj = super.put(key,value);
System.out.println("inside OrderedHashTable Put method index size = " + index.size());
return obj;
public synchronized Object remove(Object key){
int indx = index.indexOf(key);
index.removeElementAt(indx);
Object obj = super.remove(key);
return obj;
public synchronized Enumeration getOrderedEnumeration(){
return index.elements();
public synchronized Object getByIndex(int indexValue){
Object obj1 = index.elementAt(indexValue);
Object obj2 = super.get(obj1);
return obj2;
public synchronized int indexOf(Object key){
return index.indexOf(key);
public synchronized int getIndexSize() {
return index.size();
}Everything seemed to work fine util I tried to add objects using a "for" loop such as this one :
private synchronized void testOrderedHashTable(){
OrderedHashTable test = new OrderedHashTable();
for (int i = 1 ; i<15; i++){
System.out.println("adding Object No " + i);
String s = new String("string number = "+i);
test.put(new Integer(i),s);
System.out.println("-----------------------------------");
//try to list the objects
Enumeration e = test.getOrderedEnumeration();
while (e.hasMoreElements()){
Integer intObj = (Integer) e.nextElement();
System.out.println("nextObject Number = "+ intObj);
}Here is the console output :
Generic/JSR179: adding Object No 1
Generic/JSR179: inside OrderedHashTable Put method index size = 1
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 2
Generic/JSR179: inside OrderedHashTable Put method index size = 2
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 3
Generic/JSR179: inside OrderedHashTable Put method index size = 3
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 4
Generic/JSR179: inside OrderedHashTable Put method index size = 4
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 5
Generic/JSR179: inside OrderedHashTable Put method index size = 5
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 6
Generic/JSR179: inside OrderedHashTable Put method index size = 6
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 7
Generic/JSR179: inside OrderedHashTable Put method index size = 7
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 8
Generic/JSR179: inside OrderedHashTable Put method index size = 8
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 9
Generic/JSR179: inside OrderedHashTable Put method index size = 10
Generic/JSR179: inside OrderedHashTable Put method index size = 10
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 10
Generic/JSR179: inside OrderedHashTable Put method index size = 11
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 11
Generic/JSR179: inside OrderedHashTable Put method index size = 12
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 12
Generic/JSR179: inside OrderedHashTable Put method index size = 13
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 13
Generic/JSR179: inside OrderedHashTable Put method index size = 14
Generic/JSR179: -----------------------------------
Generic/JSR179: adding Object No 14
Generic/JSR179: inside OrderedHashTable Put method index size = 15
Generic/JSR179: -----------------------------------
Generic/JSR179: nextObject Number = 1
Generic/JSR179: nextObject Number = 2
Generic/JSR179: nextObject Number = 3
Generic/JSR179: nextObject Number = 4
Generic/JSR179: nextObject Number = 5
Generic/JSR179: nextObject Number = 6
Generic/JSR179: nextObject Number = 7
Generic/JSR179: nextObject Number = 8
Generic/JSR179: nextObject Number = 9
Generic/JSR179: nextObject Number = 9
Generic/JSR179: nextObject Number = 10
Generic/JSR179: nextObject Number = 11
Generic/JSR179: nextObject Number = 12
Generic/JSR179: nextObject Number = 13
Generic/JSR179: nextObject Number = 14
You can notice that the output seems correct until the insertion of object 9.
At this point the vector size should be 9 and the output says it is 10 elements long ...
In the final check you can notice the 9 was inserted twice ...
I think the problem has something to do with the automatic resizing of the vector but I'm not really sure. Mybe the resizing is done in a separate thread and the new insertion occurs before the vector is resized ... this is my best guess ...
I also tested this in a pure J2SE evironment and I don't have the same strange behavior
Can anybody tell me what I am doing wrong or how I could avoid this problem ?
Thanks a lot !
Cheers Alex

Am i doing anything wrong?Uhm, yes. Read the API doc for addElement() and for addAll()

• Vector, what is the problem with this code?

Vector, what is the problem with this code?
63  private java.util.Vector data=new Vector();
64  Vector aaaaa=new Vector();
74  aaaaa.addElement(new String("Mary"));on compiling this code, the error is
TableDemo.java:65: <identifier> expected
^
TableDemo.java:74: <identifier> expected
^
TableDemo.java:65: package data does not exist
^
TableDemo.java:74: package aaaaa does not exist
aaaaa.addElement(new String("Mary"));Friends i really got fed up with this code for more than half an hour.could anybody spot the problem?

I can see many:
1. i assume your code snip is inside a method. a local variable can not be declare private.
2. if you didn't import java.util.* on top then you need to prefix package on All occurance of Vector.
3. String in java are constant and has literal syntax. "Mary" is sufficient in most of the time, unless you purposly want to call new String("Mary") on purpose. Read java.lang.String javadoc.
Here is a sample that would compile...:
public class QuickMain {
public static void main(String[] args) {
java.util.Vector data=new java.util.Vector();
java.util.Vector aaaaa=new java.util.Vector();
}

• Problems with syncing  Adobe Ideas with Adobe Creative Cloud

Since yesterday (22.04.2014) I have problems with syncing Adobe Ideas (in my iPad) with Adobe Creative Cloud.

Hello,
I do not understand why there is no professional communication about the problem. I get the impression that Adobe doesn't know that many people use their App as advertised: As a quick professional sketching tool that syncs with Creative Cloud. Not to fix the problem means more people not trusting the cloud idea. I am actually a big fan of the CC, mostly because of regular updates. But the mobile apps seem to fall out of the normal update scheme. Are they not as important as the 'main software'?
When will the bug be fixed? Just to make clear: As there - up to now - is no other way to get the original idea files on the computer the adobe idea app is useless unless you fix the problem and/ or include the possibility to sync files via USB.
Meanwhile my Workaround:
You need Phoneview or another software that shows the files on your mobile device.
Open it - choose "Apps" - click on "Show all Apps" - click on "Adobe Ideas"
Than go to:
Library/Private Documents/documents/data/files/
there you find folders with cryptic names
Open the Folder
select all files in the folder and zip them
Change the extension from .zip to .idea
and voila
you can open it with Adobe Illustrator!
A long way, but for now the only solution to get the editable vector file on your computer.
Best regards
Jo Jacobs

• Problem with trees(Duplication of the parent node in creation of  children)

Hi guys i am experiencing a slight problem with the creation of trees.Here is a clear explanation of my program.I created a program that generates edges from a set of datapoints then use each and every edge that is generated to create multiple trees with the edge as the rootnode for each and every tree.Everything up to so far everything went well but the problem comes when i want the program to pick every single tree and traverse through the set of generated edges to create the children of a tree.What it does at the moment for each tree is returning the a duplication of the parent node as the child nodes and that is a problem.Can anyone related with this problem help.Your help will be appreciated.
The code
TreeNode class
package SPO;
import java.util.*;
public class TreeNode
Edge edge;
TreeNode node;
Vector childrens = new Vector();
public TreeNode(Edge edge)
this.edge = edge;
public synchronized  void insert(Edge edge)
if(edge.fromNode == this.edge.toNode)
if(node == null )
node = new TreeNode(edge);
else
node.insert(edge);
Tree class
package SPO;
import java.util.*;
public class Tree
TreeNode rootNode;
public Tree()
rootNode = null;
public Tree[]  createTrees(Vector initTrees,Vector edges)
Tree [] trees =  new Tree[initTrees.size()];
for(int c = 0;c < trees.length;c++)
trees[c] = (Tree)initTrees.elementAt(c);
for(int i = 0;i < trees.length;i++)
for(int x = 0;x < edges.size();x++)
Vector temp = (Vector)edges.elementAt(x);
for(int y = 0;y < temp.size();y++)
trees.insertNode((Edge)temp.elementAt(y));
return trees;
public void printTree(Tree tree)
System.out.print("("+tree.rootNode.edge.fromNode.getObjName()+","+tree.rootNode.edge.toNode.getObjName()+")");
Vector siblings = tree.rootNode.childrens;
for(int i = 0; i < siblings.size();i++)
TreeNode node = (TreeNode)siblings.elementAt(i);
System.out.print("("+node.edge.fromNode.getObjName()+","+node.edge.toNode.getObjName()+")");
System.out.println();
public Vector initializeTrees(Vector edges)
Vector trees = new Vector();
for(int i = 0;i < edges.size();i++)
Vector temp = (Vector)edges.elementAt(i);
for(int j = 0;j < temp.size();j++)
Tree tree = new Tree();
tree.insertNode((Edge)temp.elementAt(j));
return trees;
public synchronized void insertNode(Edge edge)
if(rootNode == null)
rootNode = new TreeNode(edge);
else
rootNode.insert(edge);
EdgeGenerator class
package SPO;
import java.util.*;
import k_means.*;
public class EdgeGenerator
public EdgeGenerator()
public Vector createEdges(Vector dataPoints)
//OrderPair orderPair = new OrderPair();
Vector edges = new Vector();
for(int i = 0;i < dataPoints.size()-1 ;i++)
Vector temp = new Vector();
for(int j = i+1;j < dataPoints.size();j++)
//Create an order of edges
Edge edge = new Edge((DataPoint)dataPoints.elementAt(i),(DataPoint)dataPoints.elementAt(j));
return edges;
Edge class
package SPO;
import k_means.*;
public class Edge
public DataPoint toNode;
public DataPoint fromNode;
public Edge(DataPoint x,DataPoint y)
if (x.getX() > y.getX())
this.fromNode = x;
this.toNode = y;
else
this.fromNode=y;
this.toNode = x;
Entry Point
package SPO;
import java.util.*;
import k_means.*;
public class Tester {
public static void main(String[] args)
Vector dataPoints = new Vector();
dataPoints.add(new DataPoint(104.6, "Pine apple"));
dataPoints.add(new DataPoint(94.1, "W grape"));
dataPoints.add(new DataPoint(84.8, "R Grape"));
EdgeGenerator eg = new EdgeGenerator();
Vector edges = eg.createEdges(dataPoints);
Tree treeMaker = new Tree();
Vector partialTrees = treeMaker.initializeTrees(edges);
Tree [] trees = treeMaker.createTrees(partialTrees,edges);
for(int i = 0;i < trees.length;i++)
treeMaker.printTree(trees[i]);
The program output
Each and every "@" symbol represents the start of a tree
@(Orange,Lemmon)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)
@(Orange,Coke)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)
@(Orange,Pine apple)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)
@(Orange,W grape)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)
@(Orange,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
@(Orange,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
@(Orange,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
@(Orange,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
@(Orange,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(Orange,Cocoa)(Cocoa,Pawpaw)
@(Orange,Pawpaw)
@(Lemmon,Coke)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)
@(Lemmon,Pine apple)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)
@(Lemmon,W grape)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)
@(Lemmon,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
@(Lemmon,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
@(Lemmon,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
@(Lemmon,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
@(Lemmon,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(Lemmon,Cocoa)(Cocoa,Pawpaw)
@(Lemmon,Pawpaw)
@(Coke,Pine apple)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)
@(Coke,W grape)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)
@(Coke,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
@(Coke,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
@(Coke,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
@(Coke,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
@(Coke,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(Coke,Cocoa)(Cocoa,Pawpaw)
@(Coke,Pawpaw)
@(Pine apple,W grape)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)
@(Pine apple,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
@(Pine apple,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
@(Pine apple,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
@(Pine apple,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
@(Pine apple,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(Pine apple,Cocoa)(Cocoa,Pawpaw)
@(Pine apple,Pawpaw)
@(W grape,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
@(W grape,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
@(W grape,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
@(W grape,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
@(W grape,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(W grape,Cocoa)(Cocoa,Pawpaw)
@(W grape,Pawpaw)
@(Appletizer,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
@(Appletizer,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
@(Appletizer,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
@(Appletizer,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(Appletizer,Cocoa)(Cocoa,Pawpaw)
@(Appletizer,Pawpaw)
@(R Grape,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
@(R Grape,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
@(R Grape,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(R Grape,Cocoa)(Cocoa,Pawpaw)
@(R Grape,Pawpaw)
@(Sprite,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
@(Sprite,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
@(Sprite,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(Sprite,Cocoa)(Cocoa,Pawpaw)
@(Sprite,Pawpaw)
@(Strawbery,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
@(Strawbery,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(Strawbery,Cocoa)(Cocoa,Pawpaw)
@(Strawbery,Pawpaw)
@(Stone,Yam)(Yam,Cocoa)(Yam,Cocoa)
@(Stone,Cocoa)(Cocoa,Pawpaw)
@(Stone,Pawpaw)
@(Yam,Cocoa)(Cocoa,Pawpaw)
@(Yam,Pawpaw)
@(Cocoa,Pawpaw)

Your program description makes no sense. What exactly is it supposed to do?
Your errors make no sense. What is it doing wrong?
Your program output makes no sense. Look up pre-order, in-order, and post-order notation for representing trees. Pick one of those that you think would be best. I would go with pre-order. Because what you are doing isn't understandable.
By the way, I think your concept of a tree is flawed. A node in a tree has 3 things. it has a reference to its parent, it has references to any of its children, and it has some key value that represents the node (if each node were represented by numbers, the value would be an integer or something). In the case of the root, its reference to its parent is null. I don't know what you are doing with your tree, but it is highly confusing.

• Problem with addRow and MultiLine Cell renderer

Hi ,
Ive a problem with no solution to me .......
Ive seen in the forum and Ivent found an answer.......
The problem is this:
Ive a JTable with a custom model and I use a custom multiline cell renderer.
(becuse in the real application "way" hasnt static lenght)
When I add the first row all seem to be ok.....
when I try to add more row I obtain :
java.lang.ArrayIndexOutOfBoundsException: 1
at javax.swing.SizeSequence.insertEntries(SizeSequence.java:332)
at javax.swing.JTable.tableRowsInserted(JTable.java:2926)
at javax.swing.JTable.tableChanged(JTable.java:2858)
at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableMo
del.java:280)
at javax.swing.table.AbstractTableModel.fireTableRowsInserted(AbstractTa
bleModel.java:215)
at TableDemo\$2.actionPerformed(TableDemo.java:256)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
64)
at javax.swing.AbstractButton\$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1817)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5134)
at java.awt.Component.processEvent(Component.java:4931)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3639)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1590)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
This seems to be caused by
table.setRowHeight(row,(getPreferredSize().height+2)); (line 164 of my example code)
About the model I think its ok.....but who knows :-(......
Example code :
import javax.swing.*;
import javax.swing.table.*;
import java.text.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TableDemo extends JFrame {
private boolean DEBUG = true;
MyTableModel myModel = new MyTableModel();
MyTable table = new MyTable(myModel);
int i=0;
public TableDemo() {
super("TableDemo");
JButton bottone = new JButton("Aggiungi 1 elemento");
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
//table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this window.
public void windowClosing(WindowEvent e) {
System.exit(0);
class MyTable extends JTable {
MultiLineCellRenderer multiRenderer=new MultiLineCellRenderer();
MyTable(TableModel tm)
super(tm);
public TableCellRenderer getCellRenderer(int row,int col) {
if (col==1) return multiRenderer;
else return super.getCellRenderer(row,col);
class MyTableModel extends AbstractTableModel {
Vector data=new Vector();
final String[] columnNames = {"Name",
"Way",
public int getColumnCount() { return 3; }
public int getRowCount() { return data.size(); }
public Object getValueAt(int row, int col) {
Vector rowdata=(Vector)data.get(row);
return rowdata.get(col); }
public String getColumnName(int col) {
return columnNames[col];
public void setValueAt (Object value, int row,int col)
//setto i dati della modifica
Vector actrow=(Vector)data.get(row);
actrow.set(col,value);
this.fireTableCellUpdated(row,col);
public Class getColumnClass(int c)
return this.getValueAt(0,c).getClass();
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
if (col == 1)
return false;
else
return true;
public void addRow (String name,ArrayList path,Double dead) {
Vector row =new Vector();
row.add(name); //!!!Mi tengo questo dato da utilizzare come key per andare a
//prendere il path nella lista dei paths di Project
//(needed as key to retrive data if name in col. 1 is changed)
//Inspector.inspect(this);
System.out.println ("Before firing Adding row...."+this.getRowCount());
this.fireTableRowsInserted(this.getRowCount(),this.getRowCount());
public void delRow (String namekey)
for (int i=0;i<this.getRowCount();i++)
if (namekey.equals(this.getValueAt(i,3)))
data.remove(i);
this.fireTableRowsDeleted(i,i);
//per uscire dal ciclo
i=this.getRowCount();
public void delAllRows()
int i;
int bound =this.getRowCount();
for (i=0;i<bound;i++)
{data.remove(0);
System.out.println ("Deleting .."+data);
this.fireTableRowsDeleted(0,i);
class MultiLineCellRenderer extends JTextArea implements TableCellRenderer {
private Hashtable rowHeights=new Hashtable();
public MultiLineCellRenderer() {
setEditable(false);
setLineWrap(true);
setWrapStyleWord(true);
//this.setBorder(new Border(
public Component getTableCellRendererComponent(JTable table,Object value,                              boolean isSelected, boolean hasFocus, int row, int column) {
//System.out.println ("Renderer called"+value.getClass());
if (value instanceof ArrayList) {
String way=new String     (value.toString());
setText(way);
TableColumn thiscol=table.getColumn("Way");
//System.out.println ("thiscol :"+thiscol.getPreferredWidth());
//setto il size della JTextarea sulle dimensioni della colonna
//per quanto riguarda il widht e su quelle ottenute da screen per l'height
this.setSize(thiscol.getPreferredWidth(),this.getPreferredSize().height);
// set the table's row height, if necessary
//System.out.println ("Valore getPreferred.height"+getPreferredSize().height);
if (table.getRowHeight(row)!=(this.getPreferredSize().height+2))
{System.out.println ("Setting Row :"+row);
System.out.println ("Dimension"+(getPreferredSize().height+2));
System.out.println ("There are "+table.getRowCount()+"rows in the table ");
if (row<table.getRowCount())
table.setRowHeight(row,(getPreferredSize().height+2));
else
setText("");
return this;
/**Custom JTextField Subclass che permette all'utente di immettere solo numeri
class WholeNumberField extends JTextField {
private Toolkit toolkit;
private NumberFormat integerFormatter;
public WholeNumberField(int value, int columns) {
super(columns);
toolkit = Toolkit.getDefaultToolkit();
integerFormatter = NumberFormat.getNumberInstance(Locale.US);
integerFormatter.setParseIntegerOnly(true);
setValue(value);
public int getValue() {
int retVal = 0;
try {
retVal = integerFormatter.parse(getText()).intValue();
} catch (ParseException e) {
// This should never happen because insertString allows
// only properly formatted data to get in the field.
toolkit.beep();
return retVal;
public void setValue(int value) {
setText(integerFormatter.format(value));
protected Document createDefaultModel() {
return new WholeNumberDocument();
protected class WholeNumberDocument extends PlainDocument {
public void insertString(int offs,
String str,
AttributeSet a)
char[] source = str.toCharArray();
char[] result = new char[source.length];
int j = 0;
for (int i = 0; i < result.length; i++) {
if (Character.isDigit(source))
result[j++] = source[i];
else {
toolkit.beep();
System.err.println("insertString: " + source[i]);
super.insertString(offs, new String(result, 0, j), a);
ActionListener Add_Action = new ActionListener() {
public void actionPerformed (ActionEvent e)
ArrayList way =new ArrayList();
public static void main(String[] args) {
TableDemo frame = new TableDemo();
frame.pack();
frame.setVisible(true);

In the addRow method, change the line
this.fireTableRowsInserted(this.getRowCount(),this.getRowCount()); to
this.fireTableRowsInserted(data.size() - 1, data.size() - 1);Sai Pullabhotla

• Problem with Javascript in JSP

Hi Guys,
I have this problem with my JSP page. I am using a javascript function
which calls a function within a bean. The problem that I have is that I get an error when trying to call the following function :
function refDataTypes_onchange()
Vector empNames = DBQuery.getResult();
I get a runtime error at the line Vector empNames = DBQuery.getResult;
Any ideas would be much appreciated.
Below is the whole code:
FRank
<%@ page contentType="text/html;charset=WINDOWS-1252"%>
<%@ page import="java.util.*, java.lang.*" %>
<%-- Declare the java bean for the countries to be queried --%>
<jsp:useBean id="DBQuery" class="DBQuery" scope="page" />
<%-- Bean property searchCondition is not set to query countries --%>
<jsp:setProperty name="DBQuery" property="searchCondition" />
<%
Vector empNames = DBQuery.getResult();
%>
<HTML>
<BODY BGCOLOR="GREY">
<SCRIPT LANGUAGE="JavaScript1.1">
function refDataTypes_onchange()
Vector empNames = DBQuery.getResult();
</SCRIPT>
<FORM NAME = form1>
Please enter in the following details
<p>
Reference Type :::====
<select name="refDataTypes" onchange="refDataTypes_onchange()">
<option value ="1"></option>
<% for(Enumeration enum = empNames.elements();enum.hasMoreElements();)
String nextEmpName = (String)enum.nextElement();
%>
<option value =<%=nextEmpName%>><%=nextEmpName%></option>
<%
%>
</select>
<BR>
<BR>
Emp No
<INPUT TYPE="text" NAME=txtAge >
<BR>
<BR>
<INPUT TYPE="button" VALUE="Check Details" NAME=butCheckForm >
</FORM>
</BODY>
</HTML>

I need my JSP to do the following :
When a user selects a option from a select list. There is a textfield which I want to populate based on the option that thas been selected from the list.
I tried the following :
<% Vector empNames = DBQuery.getResult(); %>
and it does not even go into the bean.
Will this work if I refresh the page?

### Maybe you are looking for

• Asset reversal using FB08

I use ab01 to create some asset retirement, five assets sucessfully retired, now I use fb08 to reverse the documents. is it the right procedure? I know we should use ab08, but Since we already use fb08 to  reverse in production server. any impact or

• Installing Oracle Apps 11.5.5: rapidwiz problem

Hi, I am trying to install Oracle Applications 11.5.5 on Linux Red Hat 7.1. I know this is not supported but my client wants 11.5.5 and the only Red Hat O/S it is certified to run on is 7.1 I have the following problem: rapidwiz calls runWizard.sh, w

• Task status: Not Authorized

Hello: I just upgraded from ARD2 to ARD3 and am no longer able to generate reports. Whenever I try, the Task Status column reads; Not Authorized (with a red exclaimation point). I am able to observe and control computers, but cannot generate reports,

• Patching unused software components

Hello, We are a relatively new SAP customer and began our implementation with ERP 2005 (not an upgrade from R/3).  At the advice of someone who wasn't familiar with the changes regarding the former Industry Solution Add-Ons versus the new Industry an

• Why does Bridge always lose track of the Favorites folders I put into it?

(Latest version of Bridge) I haven't used Bridge in a while because of this problem. When you click on one of your Favorites folders in the panel on the far left side, the folder comes up with a question mark and it can't find anything! Why does this