• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6426
  • Last Modified:

Can I convert String to Integer in J2ME?

Can I convert String to Integer in J2ME?

I retreive a record from recordStore and want to convert the record to Interger and pass to another class.. Is this possible?
0
redcoder
Asked:
redcoder
  • 9
  • 8
  • 5
  • +1
6 Solutions
 
CEHJCommented:
Integer i = new Integer("3");
0
 
redcoderAuthor Commented:
Or to make it easier , I will pass the record to second class and convert it to Integer in that second class
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Integer i = new Integer ( new String ( recordStore.getRecord ( recordID ) ) ) ;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
redcoderAuthor Commented:
 public Integer getLastQuest()
  {
   
    try
    {
          Integer numOfRcd = new Integer(recordStore.getNumRecords());
   
   
          return numOfRcd;
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return numOfRcd;
    }
   
  }

gives me error:


 cannot resolve symbol
symbol  : variable numOfRcd
location: class PersistantData
      return numOfRcd;
0
 
CEHJCommented:
Integer numOfRcd = null;
try
    {
         numOfRcd = new Integer(recordStore.getNumRecords());
   
   
         return numOfRcd;
    }

.........
0
 
TimYatesCommented:
public Integer getLastQuest()
  {
    Integer numOfRcd = null ;
    try
    {
         numOfRcd = new Integer(recordStore.getNumRecords());
         return numOfRcd;
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return numOfRcd;
    }
  }
0
 
TimYatesCommented:
Even neater:

  public Integer getLastQuest()
  {
      Integer numOfRcd = null ;
      try
      {
         numOfRcd = new Integer(recordStore.getNumRecords());
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
      return numOfRcd;
  }
0
 
TimYatesCommented:
so that will return null on exception
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Why to return from the try/ catch block as well? Better to write the return statement only once, outside both of them :) that's how some companies' coding-standards mandate anyway ;-)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Oh :)
0
 
redcoderAuthor Commented:
Can i perform calculation on this Integer type?or should i use int type?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You can't. You need to use int.
0
 
redcoderAuthor Commented:
so can i convert Integer to int? and how?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Integer integerObj = new Integer ( value from record-store ) ;
int i = integerObj.intValue () ;
0
 
CEHJCommented:
int i = x.intValue();
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Sorry, I didn't check that on J2ME. Will have to see if the method-name is the same. I hope so (you can check).
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I'm assuming: "value from record-store" is not an 'int' otherwise you already have the 'int' there. If you are using recordStore.getNumRecords (), I guess it returns an 'int' anyway. If you have a String from the record-store and you want to convert it to an 'int', you can either make an Integer object and use intValue () as shown, or simply use Integer.parseInt ( stringValue ) ;
0
 
CEHJCommented:
:-)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> int i = x.intValue();

Was that any different from what I posted just before it?
0
 
redcoderAuthor Commented:
Sorry, I didn't try on it.. I just use it cause its simple...
0
 
redcoderAuthor Commented:
Hi mayankeagle,

I see your point... basically you have
int i = integerObj.intValue () ;  similar to int i = x.intValue();

Sorry I didn't realize that... I should have split the point to you.. I made a mistake..
Do you want me to write to Admin to change it ? But I am not sure it is allowable or not?

My apologize...

:-|
0
 
Mayank SAssociate Director - Product EngineeringCommented:
It is possible. I have asked Venabili, our page-editor, to do it:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21765176.html
0
 
redcoderAuthor Commented:
Hi mayankeagle ,
I have request for edit in the following topic:

http://www.experts-exchange.com/Community_Support/Feedback/Q_21788589.html
0
 
redcoderAuthor Commented:
Hi CEHJ,

I hope you understand the situation, due to the policy that first come first rewarded.
0
 
CEHJCommented:
Don't worry
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 9
  • 8
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now