×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Load file Images into a List!

    Hi all,
    I am stuck (again...)!
    I am trying to load few thumbnails images to a List.
    What I do is call an openImage method that basically enqueue the loading and creation of the images as an operation (like in the classic file connection example)

    I have the loading and creation of the Image in the same Thread:
    Code:
    new Thread(){
     public void run(){
        try{
        currentRoot = (FileConnection) Connector.open(
                                            rootThumb+ parameter+"_thumb.png", Connector.READ);
                                    InputStream fis = currentRoot.openInputStream();
                                    long overallSize = currentRoot.fileSize();
                                    
                                    int length = 0;
                                    byte[] imageData = new byte[0];
                                    while (length < overallSize) {
                                        byte[] data = new byte[1024];
                                        int readAmount = fis.read(data, 0, 1024);
                                        byte[] newImageData = new byte[imageData.length + 1024];
                                        System.arraycopy(imageData, 0, newImageData, 0, length);
                                        System.arraycopy(data, 0, newImageData, length, readAmount);
                                        imageData = newImageData;
                                        length += readAmount;
                                    }
                                    loadedLabel = Image.createImage(imageData, 0, length);
                                    loaded=true;
                                    if (deg!=null){
                                        Wine wine = DataManager.getInstance().getWineById(deg.getWineId());
                                        midlet.get_listDeg().append(wine.getWineId()+" "+wine.getWineName()+" "+wine.getWinerName()+" "+wine.getYearProduction()+" "+midlet.parseDate(deg.getDate()), loadedLabel);
                                        if (midlet.get_listDeg().size()==DataManager.getInstance().getNumof(DataManager.DEGUSTATION, deg.getCarnetId())){
                                            midlet.getDisplay().setCurrent(midlet.get_listDeg());
                                        } /*else {
                                            Alert alert = new Alert("Info", "Size: " + midlet.get_listForm().size()+" vs. "+DataManager.getInstance().getNumof(DataManager.DEGUSTATION, deg.getCarnetId()),null, AlertType.INFO);
                                            midlet.getDisplay().setCurrent(alert, midlet.get_listMain());
                                        }*/
                                    } else {
                                        midlet.showDeg(display);
                                    }
                                    fis.close();
                                    currentRoot.close();
                                    deg=null;
                                } catch (IOException e) {
                                    //midlet.showError(e);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    //midlet.showError(e);
                                }
                            }
                        }.start();
                        
                        break;
                    case DELETE_OP:
                        //deleteCurrent();
                        break;
                    case RENAME_OP:
                        if (parameter != null) {
                            //renameCurrent(parameter);
                        } else {
                            //renameCurrent();
                        }

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: Load file Images into a List!

    Hello sandro1972,

    what's the problem in detail? Do you get some exception (for example regarding path)?

    Regards,
    r2j7

  3. #3
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Load file Images into a List!

    Sorry, I posted it before finishing it and I couldn't change it or delete it (I don't have permission apparently). The problem "was" that I was adding loadedLabel that was a class variable meaning that the first finishing thread would change the variable Image. So the loaded images where quite erratic as thread runs.
    I used a methid variable and now everything is OK
    Sorry

    Alex

  4. #4
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Thumbs up Re: Load file Images into a List!

    Hello Alex,

    sure thing, no problem. Glad to hear that the problem got solved eventually!

    In addition: thank you for introducing the workaround/cause of the problem, this helps other developers which may come across with similar issue(s).

    Regards,
    r2j7
    Last edited by r2j7; 2008-01-10 at 09:26.

Similar Threads

  1. cannot able to play a video file.
    By shalini.mishra in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2006-11-13, 16:54
  2. How can I compress .jar file to load .m3g files?
    By vinnahang in forum Mobile Java General
    Replies: 1
    Last Post: 2006-04-09, 15:38
  3. 6680 and bluetooth service profiles
    By ceruault in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-08, 22:24
  4. list box example
    By murmur20 in forum Symbian User Interface
    Replies: 1
    Last Post: 2004-11-09, 04:42

Posting Permissions

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