Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified
Accepted Solution

problem with vector

hello

 

i write some code for get value from vector and store in String array,

but when i convert it into String it show me classcastException.

so please help me to solve it.

 

code:

 

                    String[] elem=new String[data7.size()];
                    System.out.println("size="+data7.size());
                    while(f < data7.size())
                    {
 
                        elem[f]=(String)data7.elementAt(f);
                        
                        System.out.println("data="+elem[f]);
                       
                        ++f;      
                    }  

 

note: here data7 is vector.

 

Developer
Posts: 16,786
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem with vector

most likely the element in the vector is not a string...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem with vector

but i store string value in vector.

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: problem with vector

"but i store string value in vector."

 

Clearly not, becuase if you did, you would not get a cast exception!  Assuming the exception is thrown by this line:

elem[f]=(String)data7.elementAt(f);

This sort of problem is usally pretty easy to spot using the debugger.  Have you tried that?

 

Which line throws the exception. 

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem with vector

i debugg it before post it on forum  and i know that below line show me error.

 

elem[f]=(String)data7.elementAt(f);

 

if i write below code it works but show different ouput.

 

elem[f]=data7.elementAt(f).toString();

 

and also this,

elem[f]=(String)data7.elementAt(f).toString();

 

Developer
Posts: 16,786
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem with vector

as every object has a toString method you get a string, but as the default implementation returns the object id it is not very useful.

do you know what a breakpoint is?
or even a simple sysout with object.getClass would help you here.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem with vector

thanks for reply

 

i have one more question .

 

how i can delete single data  from Persistent store?

 

please if u have code then give me.

 

 

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: problem with vector

PersistentStore - destroyPersistentObject(long key)

 

I'm sure you can create you own code for this. 

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem with vector

hi peter,

 

PersistentStore - destroyPersistentObject(long key)

 

if i write above code ,it deletes  key.

If i delete this key then all  data  stored in persitent key is deleted.

But i want  to  delete at time only one data not all.

please reply.

Developer
Posts: 16,786
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem with vector

retrieve the data collection, modify it and store it again
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter