Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3873894
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:05:22+00:00 2026-05-19T22:05:22+00:00

I am using TimerTask and ImageLoader class to load n image to an image

  • 0

I am using TimerTask and ImageLoader class to load n image to an image item.

public class Imageloader implements Runnable{

    private ImageItem item=null;
    private String url=null;

    /*
     * initializes the imageItem
     */
    public Imageloader(ImageItem item,String url){
            this.item=item;
            this.url=url;
    }


    private Image getImage(String url) throws IOException {
        item.setLabel(item.getLabel()+12);
        System.out.println("Test 5");
            HttpConnection connection = null;
            DataInputStream inp = null;
            int length;
            byte[] data;
            try {System.out.println("Test 6");
                    connection = (HttpConnection) Connector.open(url);
                    item.setLabel(item.getLabel()+13);
                    connection.getResponseMessage();
                    System.out.println("Test 7");
                    length = (int) connection.getLength();
                    item.setLabel(item.getLabel()+14);
                    System.out.println("Length is "+length);
                    System.out.println("Test 8");
                    data = new byte[length];
                    inp = new DataInputStream(connection.openInputStream());
                    item.setLabel(item.getLabel()+15);
                    System.out.println("Test 9");
                    inp.readFully(data);
                    item.setLabel(item.getLabel()+16);
                    System.out.println("Test 10");
                    return Image.createImage(data, 0, data.length);
            }
            finally {
                if (connection != null) connection.close();
                if (inp != null)inp.close();

            }
    }


    public void run() {
        System.out.println("Test 1");
        Image image=null;
        try{
                if (url!=null){
                    System.out.println("Test 2");
                        image=getImage(url);
                        System.out.println("Test 3");
                        item.setImage(image);
                        item.setLabel(item.getLabel()+17);
                        System.out.println("Test 4");
                }
                else{
                    item.setAltText("Map address specified is incorrect");
                }
        }
        catch(IOException e){
                item.setAltText("Map cannot be loaded now");
        }

    }

}

public class MapTimer extends TimerTask{

    DatagramConnection connection=null;
    String message=null;
    Imageloader imageretriever;
    ImageItem item=null;

    MapTimer (DatagramConnection connection,String message,ImageItem Img_map ){
        this.connection=connection;
        this.message=message;
        this.item=Img_map;
        item.setLabel(item.getLabel()+1);
        System.out.println("Map is initizlized...");
    }


    public void run() {
        System.out.println("Map starting...");
         item.setLabel(item.getLabel()+2);
        String serverquery=null;
        try {
             item.setLabel(item.getLabel()+3);
            sendMessage(message);
             item.setLabel(item.getLabel()+4);
            //serverquery=receiveMessage() ;
             item.setLabel(item.getLabel()+5);
            //item.setLabel(" Loading...." );
            //formatmessage(serverquery);
               String url="http://maps.google.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap"+
"&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318"+
"&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false";
            Imageloader Im=new Imageloader(item,url);
             item.setLabel(item.getLabel()+6);
            (new Thread(Im)).start();
             item.setLabel(item.getLabel()+7);
            System.out.println("server map query is::: "+serverquery);
        } catch (IOException ex) {
            System.out.println("Error2"+ex);
        }
          catch(Exception e){
            System.out.println("Error3"+e);
       }
    }


     /*
     * Sends a message via UDP to server
     */
    private void sendMessage(String message) throws IOException{
        Datagram packet_send=null;
        if (connection != null){
            byte[] packetsenddata=message.getBytes();
            packet_send = connection.newDatagram(packetsenddata,packetsenddata.length);
            connection.send(packet_send);
            packet_send = null;
        }
    }
}

This is how I set the Timer;

 MapTimer maptimer=new MapTimer (connection,mapquery ,Img_map );
                    Timer timer=new Timer();
                    timer.schedule(maptimer, 5000, 100000);

It’s working fine with the enulator but as I deploy it on my mob,the image is not loading..
The image label is somewhat like Stopping 234567234567 which implies that my timer is running fine. It is not entering the ImageLoader class… How do get to load this image?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:05:23+00:00Added an answer on May 19, 2026 at 10:05 pm

    This is difficult to say without further debuggind. I recommend you to use Micrologger + a web server, in order to debug your midlets on the device.

    Looking to your code, I suspect of this line length = (int) connection.getLength();. Could it fail on Nokia’s IO library implementation?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP, I'd like to convert a string containing a Roman number into its
using linux commands, I have a quoted csv file which I sorted by first
using ... $this->getInvokeArg('bootstrap')->getOptions(); .. to retrieve my config settings from application.ini (using Zend Framework
Using CouchDB 1.0.1. I have DELETEd some documents, then I PUT some other documents
Using the Facebook PHP SDK, what steps do I need to take to allow
Using VisualBrush, I am taking snapshots of a Window that contains a TabControl. Snapshot
Using Maven to build my project under windows works fine, but when I build
Using Foursquare API "Venue" service.. I am parsing nearByVenue details like shop, restaurant etc.
Using Moq, RhinoMocks or a similar framework, is there a way to configure a
Using the Tab Bar template in Xcode 4, each ViewController is created automatically, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.