Strange TextField problem

I’m perfectly willing to believe I’m doing something stupid here, but I don’t see it… Would appreciate it if someone can tell me what I’m doing wrong…

I have created a HashMap where the Value is a Vaadin TextField object. Each TextField contains a string like “0”, “1”, “2”, “3”…
The user can reorder my objects by changing the values in these text fields and touching a button.

The code that tries to process this information looks like this:

public void buttonClick(ClickEvent event) {
			GraphFrame gf = (GraphFrame) bGenpng.getData();
			Integer ii = null;
			GraphLine jgl = null;
			String s = null;
			TextField tf = null;

			for(int i = 0; i < myJG.numGraphLines(); i++){
				jgl = myJG.getGraphLine(i);
				tf = hm_LineOrder.get(jgl);    // *** Get the TextField from the map
				Logger.info("" + i + ") Value: " + tf.getValue());

				Logger.info("Line " + i +  " moves to position " + tf.getValue());
			
				s = (String) tf.getValue();      // ****** THIS IS LINE 852 (see traceback, below)
				Logger.info("\tS = " + s);
				Logger.info("\tT = " + s.trim());
				ii = Integer.parseInt(s.trim());

				Logger.info("II = " + ii.intValue());
				jgl.setLineOrder(ii.intValue());
			}
			reGenerateGraph(myDispatcher, myJG);
		}

This seems straightforward enough… But when I run the program, WITHOUT changing any values in the text fields, I get this in my log file when
I hit the button:

  1. Value: 0
    Line 0 moves to position 0
    Dec 7, 2011 2:08:50 PM com.vaadin.Application terminalError
    SEVERE: Terminal error:
    com.vaadin.event.ListenerMethod$MethodException
    Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    … many more lines of traceback…

Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at com.verisign.jart.GraphFrame$16.buttonClick(GraphFrame.java:852)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

I’ve been around and around on this - I even tried casting tf.getValue() to an Integer, and of course the error is ‘Can’t cast a String to an Integer’ - which makes perfect sense. So what am I doing wrong???

I have successfully pulled string data out of text field objects in other parts of my program - this has to be something stupid that I’m doing here…

Thanks in advance,

nbc

I think the more relevant code would be the one very you build your map and call setValue() for your TextFields. And please use the code markup around your code snippets.

And that solved the problem… Thanks! My texfield.setValue was called with an int - I was under the impression that that would be converted to a String, but apparently not. I changed the call to setValue(“” + get_my_int()) and now it works.

Side note - where do I find the code markup information - I’ll certainly use that in the future…

thanks again

nbc

In the editor toolbar there’s a button with two red angle brackets. Just next to the smiley button.

Got it - thanks!

nbc