Hey,
i'm trying to use the method getValueAt(int row, int column) from Class DefaultTableModel .
This method returns Object value, but i want to get an int value.

so can anyone suggest what class to use in order to convert the Object value to int ?

Type cast Object to Integer:

Integer integ = (Integer)objectValue;
integ.intValue();

I've tried it bu it gave me an exeptions as follows:
ValueEntryFrame.<init>(ValueEntryFrame.java:83)

This is wut i wrote: ( trying to copy content of a table into a matrix of type int)

Integer integ;
model = new DefaultTableModel(data,colNames);
table = new JTable(model);
      
for (int k=0; k<row; k++ )
   for (int l=0; l<col; l++)
    {  
         integ = (Integer)model.getValueAt(k,l);
         matrix[k][l]= integ.intValue();
     }

what could be the problem ?

Post part of the code where you get the exceptions, as well as the printStackTrace()

Your suggestion is working well ... i had a problem with the declaration of my matrix.

Thank you v.much for your help.

i didnt know if to open a new thread .. but i'm having another problem .. probably casting will do it, but i'm not sure.

i'm filling a stack with many variable: Strings and int
when i pop, it returns me a value of type Object. so my Questions is: how can i know if that returned value is a string or an int !?

if (returnedObject instanceof String)
   String a = (String)returnedObject;
else
   Integer b = (Integer)returnedObject;

OH great ... many thanks

i didnt know if to open a new thread .. but i'm having another problem .. probably casting will do it, but i'm not sure.

i'm filling a stack with many variable: Strings and int
when i pop, it returns me a value of type Object. so my Questions is: how can i know if that returned value is a string or an int !?

The question you should be asking is why you are putting strings and ints into a single stack? In most cases you should use an appropriate interface type for the collection that effectively represents what you expect to do with those objects. Obviously you are placing them in a collection for some reason - the interface should reflect that reason. If you have to use a lot of branched instanceof logic to process those items, you probably need to re-examine your abstraction of the operation for consistency and cohesion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.