×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    6

    Exclamation currency converter-updated

    Dear all,
    please give some idea for converting the currency and currency value should be updated from any website,
    using J2ME,
    or suggest me that is it possible to use any webserivces for that.

    pls help me out guys.
    note : i did the currency conversion using some default value.

    Regards,
    Siv

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: currency converter-updated

    Hi Siv,

    There are different ways you can create a currency converter in Java ME.

    The following methods require that you find a server that supports the suggested method for requesting the currency conversion and that you adjust your request to a format that is understood by the server (so a description of the service should be provided):

    1. Via HTTP and GET by passing the arguments of your request to the URL (after you have URL encoded them)
    2. Via HTTP and POST by opening both an output stream to send your request and an input stream to receive the response.
    3. Via XML-RPC and SOAP by using JSR-172, the Web Services API.


    The following method does not require you to send a request, but if the format of the page you are reading from is changed, you might no longer be able to retrieve properly the values:

    1. Simply by reading over HTTP a web site that lists today's exchange rates for the target currencies.


    You can find more about HTTP in Java ME and how to perform requests using either the POST or GET method here

    There are also some Articles with example code for HTTP GET and POST on the Wiki here and here respectively

    You can find the Java Documentation regarding XML-RPC for Java ME (JSR-172) here

    If you go down the XML-RPC road, make sure that you read the JSR-172 specifications from here

    There is also a basic tutorial for JSR-172 here

    After a short search in google, I found for example a SOAP service that you could try for currency conversion by using JSR-172 here

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    6

    Re: currency converter-updated

    thanks the reply was very useful.
    till now i can able to read the html content of a webpage but cannot able to get a particular value from the samepage.
    help me
    regards
    siv

  4. #4
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: currency converter-updated

    You could do that with Java's basic String manipulation. Assuming that you have stored the web page's contents in a String variable, you would need to identify the area of the String where you need to extract information from with the indexOf and lastIndexOf methods. Then, you could grab the value that interests you with the substring method. You can find more about String manipulation in Java here:

    http://docs.oracle.com/javase/tutori...ipstrings.html

    Keep in mind that not all Java SE's methods are supported in Java ME.

    If you need further assistance, you can share the page you are extracting values from along with the values that you need to extract, and I could provide a simple snippet.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    6

    Re: currency converter-updated

    Thanku skalogir its working ! but again i hv one small issue , my Exit command not working
    here is the code that i wrote for exit
    if(c==Exit)
    {

    destroyApp(false);
    notifyDestroyed();
    }
    if posiible give some suggestions for this .

  6. #6
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: currency converter-updated

    my Exit command not working
    What is exactly your error? What happens?

    Does your destroyApp method throw a MIDletStateChangeException ?

    What value have you assigned to Exit?

  7. #7
    Registered User
    Join Date
    Feb 2012
    Posts
    6

    Re: currency converter-updated

    {

    HttpConnection connection = null;
    InputStream inputstream = null;
    try
    {


    connection = (HttpConnection) Connector.open("www.website...");

    //HTTP Request
    connection.setRequestMethod(HttpConnection.GET);
    connection.setRequestProperty("Content-Type","//text plain");
    connection.setRequestProperty("Connection", "close");
    // HTTP Response
    System.out.println("Status Line Code: " + connection.getResponseCode());
    System.out.println("Status Line Message: " + connection.getResponseMessage());

    if (connection.getResponseCode() == HttpConnection.HTTP_OK)
    {
    System.out.println(
    connection.getHeaderField(0)+ " " + connection.getHeaderFieldKey(0));
    System.out.println(
    "Header Field Date: " + connection.getHeaderField("date"));

    String str = null;
    inputstream = connection.openInputStream();
    int length = (int) connection.getLength();
    // if (length != -1)
    // {
    // byte incomingData[] = new byte[length];
    // inputstream.read(incomingData);
    // str = new String(incomingData);
    //
    // }
    // else
    // {
    ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
    int ch = 0;
    ch = inputstream.read();

    int count;
    while ((ch = inputstream.read()) != -1)
    {
    bytestream.write(ch);
    // System.out.println("hello" + bytestream); the out put for this comes something like letter by letter the things were adding .
    // count=count+1;

    }
    // System.);
    str = new String(bytestream.toByteArray());
    System.out.println(str);
    bytestream.close();
    //}


    //System.out.println(str);

    System.out.println("no of matches" + startIndex);
    connection.close();
    }

    }
    catch(IOException error)
    {
    System.out.println("Caught IOException: " + error.toString());
    }
    finally
    {
    if (inputstream!= null)
    {
    try
    {
    inputstream.close();
    }
    catch( Exception error)
    {
    /*log error*/
    }
    }
    if (connection != null)
    {
    try
    {
    connection.close();
    }
    catch( Exception error)
    {
    /*log error*/
    }
    }
    }
    }




    and for exit i mentioned the code as exit and command is also exit .
    coding for the exit is also mentioned in previous command..
    kindly help me
    regards
    siv

  8. #8
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: currency converter-updated

    Try wrapping the code that you use for the page retrieval inside a Thread. Check the article here for more information on how to create threads.

    Also ensure that your destroyApp does not throw a MIDletStateChangedException.

    You can also try removing the following code:
    Code:
    destroyApp(false);
    entirely from your If block.

    If the error persists, please provide more information about it, i.e. let us know what you see on the screen, the device you are testing on and the SDK you are using in order to compile your code.

Similar Threads

  1. Query Dialog to handle currency.
    By giedi1 in forum Symbian
    Replies: 1
    Last Post: 2010-11-08, 11:42
  2. currency conversion problem
    By sanatkumarjain in forum Symbian
    Replies: 2
    Last Post: 2008-11-03, 12:59
  3. currency conversion problem
    By sanatkumarjain in forum Symbian
    Replies: 1
    Last Post: 2008-11-03, 10:55
  4. Currency Conversion
    By pashraj in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2007-07-18, 00:46
  5. Updated Version Of The Nokia Multimedia Converter ???
    By russell2712 in forum Tools and SDK Feedback (Closed)
    Replies: 0
    Last Post: 2006-08-29, 10:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×