cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
87
Views
0
Helpful
0
Comments
cdnadmin
Community Member
This document was generated from CDN thread

Created by: null on 31-10-2003 02:57:07 AM
I have designed an application that takes some input from the user and updates the database column. I am using an action element to get input from a number capture field "order" and substract order from stock , it updates the database fiel with an updated value. This code has the following errors. It throws a NumberFormatException at 'quantity'. Can you please help me to fix this error.
I couldn't find anything unusual in the code.
java.lang.NumberFormatException: quantity
at java.lang.Integer.parseInt(Integer.java:409)
at java.lang.Integer.parseInt(Integer.java:458)
at Order.doAction(Order.java:23)
[code:1:71e4c62bea]
import com.audium.server.proxy.*;
import com.audium.server.session.*;
import com.audium.server.session.user.*;
import com.audium.server.AudiumException;
import com.audium.server.session.*;
import com.audium.server.voiceElement.ActionElementBase;
import java.util.*;

/**
* This class is an action element that takes a number from a number capture field called "Quantity" and a integer value from a database field "quantity".
* It updates the quantity field by substracting the order from the quantity.
* It stores the updated quantity into "qty".
**/
public class Order extends ActionElementBase
{
public void doAction(java.lang.String name, ActionElementData actionAPI) throws AudiumException
{
com.audium.server.action.database.ResultSetList rsList =
(com.audium.server.action.database.ResultSetList) actionAPI.getSessionData("quantity");

int order =Integer.parseInt(actionAPI.getElementData("Quantity", "value"));

int quant = Integer.parseInt("quantity");

quant -=order ;
actionAPI.setSessionData("qty", Integer.toString(quant));
}
}
[/code:1:71e4c62bea]

Subject: RE: Number formatting
Replied by: null on 31-10-2003 04:29:03 PM
Jaison,

After a quick look at your code, it is apparent that the issue you are encountering is not related to the Audium API and rather in your Java code. Here are a couple of links to Java resources I have found very useful in helping me with my Java questions:

http://www.experts-exchange.com
http://www.jguru.com
http://java.sun.com/j2se/1.3/docs/api/index.html - The Java API Javadocs are also quite helpful

Just a quick note about your code: It looks likely the problem comes from this line:

int quant = Integer.parseInt("quantity");

Subject: RE: Number formatting
Replied by: null on 26-01-2004 06:10:09 PM
hopefully my error is a bit different ... i should be able to set any object (such as a java.lang.Integer) into session data, yes? here is my app-start-class:

[code:1:b180333c4a]
import java.lang.Integer;
import com.audium.server.AudiumException;
import com.audium.server.proxy.*;
import com.audium.server.session.*;

public class ClubResStartCall implements StartCallInterface {

public void onStartCall(CallStartAPI callStartAPI) throws AudiumException {

Integer myID = new Integer(1);
callStartAPI.setSessionData("myID", myID);

}
}
[/code:1:b180333c4a]

but i get the standard error message. the error in the error log is:

[i:b180333c4a]SERVER ERROR: An Audium element encountered an exception. The exception was: java.lang.Integer[/i:b180333c4a]

should i not be using java.lang.Integer? things are compiling fine, just not working fine ...

Subject: RE: Number formatting
Replied by: Michael Bochynski on 26-01-2004 09:07:27 PM
Hi Matthew,

The session data is set in the CallStart class, where the error occurred in an element, according to the log you provided. Make sure, that in the element accessing this particular session data there is no error. You may want to check for such errors as incorrect casting or setting the data as a TTS .

Regards,
Michael

Subject: RE: Number formatting
Replied by: null on 26-01-2004 09:21:30 PM
So the error is not from setting the session data as an integer, it's from the element consuming that data. the 'consumer' in this case is a Database element. I want that value to be what came from my StartCall class, and it should go into a query such as:

[code:1:03733e5787]select name, addr_1, addr_2
from table
where myID= {Data.Session.myID}[/code:1:03733e5787]

Does this need to be a string, then? The substitution text was unclear to me, for some reason I thought an Integer could be substituted. If there's no automatic casting, though, I guess this would have to be a String?

Subject: RE: Number formatting
Replied by: Michael Bochynski on 26-01-2004 10:27:08 PM
Hi,

You are correct. If you use your session data as a substitution in your application, the variable has to be a String type. However, you can set any object, not only [i:5eddc8df6c]java.lang.Integer[/i:5eddc8df6c], as a session data.

Regards,
Michael
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links