无法分配定时器0:没有插槽左,无法设置动态的行高 [英] Failed to allocate timer 0: no slots left and unable to set dynamic row height

查看:212
本文介绍了无法分配定时器0:没有插槽左,无法设置动态的行高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个叫屏幕 listfield

public class Main_AllLatestNews extends MainScreen {
private Database_Webservice webservice;
private String[] title, category, date, imagepath = {"no picture", "no picture", "no picture", "no picture","no picture","no picture","no picture","no picture","no picture", "no picture"};
private int[] newsid;
private List_News newslist;

public Main_AllLatestNews(final boolean needdownload) {
    super(USE_ALL_WIDTH);
    webservice = new Database_Webservice();
    add(new Custom_TopField(this, 0, -1, "", 1, 1));
    add(new Custom_BottomField(this, 0));
    add(new Custom_HeaderField(Config_GlobalFunction.latest));
    if (needdownload){
        Main.getUiApplication().pushScreen(
                new Custom_LoadingScreen(30));
        webservice.UpdateAllCatNews();          
    }else {
        webservice.LoadtodayNews(); 
        newsid = new int[webservice.news.size()];
        title = new String[webservice.news.size()];
        category = new String[webservice.news.size()];
        date = new String[webservice.news.size()];
        //imagepath = new String[webservice.news.size()];

        for (int i = 0; i < webservice.news.size(); i++) {
            newslist = (List_News) webservice.news.elementAt(i);
            newsid[i] = newslist.getID();
            title[i] = newslist.getNtitle();
            category[i] = newslist.getNewCatName();
            date[i] = newslist.getNArticalD();
            //imagepath[i] = newslist.getImagePath();
        }
        add(new Custom_ListField(newsid, title, date, category, imagepath, true));
    }
}
}

当我加入 custom_listfield 然后我得到:

无法分配定时器0:没有留下插槽

Failed to allocate timer 0: no slots left

下面是我的 listfield

public Custom_ListField(int newsid[], String title[], String date[],
        String category[], String imagepath[], boolean islatest) {
    super(0, ListField.MULTI_SELECT);
    this.newsid = newsid;
    setCallback(this);
    setBackground(Config_GlobalFunction.loadbackground("background.png"));
    this.islatest = islatest;
    rows = new Vector();

    for (int x = 0; x < title.length; x++) {
        TableRowManager row = new TableRowManager();

        titlelabel = new Custom_LabelField(title[x],
                LabelField.USE_ALL_WIDTH | DrawStyle.LEFT);
        titlelabel.setFont(Font.getDefault().derive(Font.BOLD, 23));
        row.add(titlelabel);

        datelabel = new Custom_LabelField(date[x], DrawStyle.ELLIPSIS
                | LabelField.USE_ALL_WIDTH | DrawStyle.LEFT);
        datelabel.setFont(Font.getDefault().derive(Font.BOLD, 18));
        datelabel.setFontColor(Color.GRAY);
        row.add(datelabel);

        categorylabel = new Custom_LabelField(category[x],
                DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                        | DrawStyle.LEFT);
        categorylabel.setFont(Font.getDefault().derive(Font.BOLD, 18));
        categorylabel.setFontColor(Color.RED);
        row.add(categorylabel);

        /*Bitmap imagebitmap = null;
        if (!imagepath[x].toString().equals("no picture")) {
            imagebitmap = Util_ImageLoader.loadImage(imagepath[x]);
        } else {
            imagepath[x] = "image_base.png";
            imagebitmap = Bitmap.getBitmapResource(imagepath[x]);
        }
        image = new BitmapField(imagebitmap, Field.FIELD_HCENTER
                | Field.FIELD_VCENTER);
        row.add(image);*/

        //setRowHeight(image.getBitmapHeight() + 10);
        setRowHeight(70);
        rows.addElement(row);
    }
    setSize(rows.size());
}

在此列表中,它会调用10张以上。首先我会检查了链接发送给它在其他负载本地图片。因此,该行高度必须不尽相同,但是,它不会自动设定为每个行的行高,但相同的高度设置为所有的行。我想出来的内存,因为我叫了太多的图像?但我呼吁在android系统也没问题。

In this list, it will call 10 images or more. First I will check got link send to it else load local images. So the row height must be not same, however, it does not auto set row height for each row but set a same height to all row. I think out of memory because i call too many images? but I call in android also no problem.

这是我的 ImageLoader的

public class Util_ImageLoader {

public static Bitmap loadImage(String url) {
    HttpConnection connection = null;
    InputStream inputStream = null;
    EncodedImage bitmap;
    byte[] dataArray = null;

    try {
        // can use this for BlackBerry 5.0+ :
        // connection = (HttpConnection) (new
        // ConnectionFactory()).getConnection(url).getConnection();
        connection = (HttpConnection) Connector
                .open(url + Util_GetInternet.getConnParam(),
                        Connector.READ, true);
        int responseCode = connection.getResponseCode();
        if (responseCode == HttpConnection.HTTP_OK) {
            inputStream = connection.openDataInputStream();
            dataArray = IOUtilities.streamToBytes(inputStream);
        }
    } catch (Exception ex) {
    } finally {
        try {
            inputStream.close();
            connection.close();
        } catch (Exception e) {
        }
    }

    if (dataArray != null) {
        bitmap = EncodedImage.createEncodedImage(dataArray, 0,
                dataArray.length);
        return bitmap.getBitmap();
    } else {
        return null;
    }
}
}

1)我能做些什么来减少对内存的使用?

1) What can I do to reduce the use of memory?

2)如何设置不同的行高?我设置 bitmap.getbitmapheight(),但不同的位图将有不同的高度。

2) How to set different row height? I am set bitmap.getbitmapheight() but different bitmap will have different height.

// //更新

我在模拟器9930 OS 7.0和8520 OS 5.0上运行。双方还同样的结果。真实的设备无法运行,因为在签订键也提示警告信息后,尝试进行安全的API 。我完全注释的所有图像也一样。我没有叫既不是在线还是局部图像。我认为是数据的问题?

I am running on simulator 9930 OS 7.0 and 8520 OS 5.0. Both also same result. Real Device cannot run because after signing the key also prompt the warning message try to Secure APi. I am completely commented all the images also same. I did not call neither online nor local image. I think is the data problem?

@AlanLai,你能告诉我们这是正在运行的设备,哪些操作系统?它是一个模拟器,还是真实的硬件?你为什么不尝试完全注释掉的形象。不显示任何图像(图像网络或本地图片)。看看你是否仍然得到这个问题。让我们试着来缩小正是code是这是造成你的问题。注意:请张贴关于你上面测试的设备上,在这个问题,而不是在这里评论的反应的信息。谢谢

@AlanLai, can you tell us which device this is being run on, and which OS? Is it a simulator, or real hardware? Why don't you try commenting out the image completely. Don't show any images (network images, or local images). See if you still get the problem. Let's try to narrow down where exactly the code is that's causing your problem. Note: please post the information about which device you're testing on above, in the question, not as a comment response here. Thanks

推荐答案

的问题是 Custom_ListField 。这应该延伸listfield
 而不是定制扩展管理器

public class Custom_ListField extends ListField {
private String[] title, category, date, imagepath;
private int[] newsid, catsid;
private List_News newslist;
private Bitmap imagebitmap[], localimage = Bitmap
        .getBitmapResource("image_base.png");
private BrowserField webpage;
private Custom_BrowserFieldListener listener;
private boolean islatest;

private Vector content = null;
private ListCallback callback = null;

private int currentPosition = 0;

public Custom_ListField(Vector content, boolean islatest) {
    this.content = content;
    this.islatest = islatest;
    newsid = new int[content.size()];
    title = new String[content.size()];
    category = new String[content.size()];
    date = new String[content.size()];
    imagepath = new String[content.size()];
    catsid = new int[content.size()];
    imagebitmap = new Bitmap[content.size()];

    for (int i = 0; i < content.size(); i++) {
        newslist = (List_News) content.elementAt(i);
        newsid[i] = newslist.getID();
        title[i] = newslist.getNtitle();
        category[i] = newslist.getNewCatName();
        date[i] = newslist.getNArticalD();
        imagepath[i] = newslist.getImagePath();

        if (!imagepath[i].toString().equals("no picture")) {
            imagebitmap[i] = Util_ImageLoader.loadImage(imagepath[i]);
        } else {
            imagebitmap[i] = localimage;
        }
        catsid[i] = newslist.getCatID();
    }

    initCallbackListening();
    this.setRowHeight(localimage.getHeight() + 10);
}

private void initCallbackListening() {
    callback = new ListCallback();
    this.setCallback(callback);
}

private class ListCallback implements ListFieldCallback {

    public ListCallback() {
        setBackground(Config_GlobalFunction
                .loadbackground("background.png"));
    }

    public void drawListRow(ListField listField, Graphics graphics,
            int index, int y, int width) {
        currentPosition = index;
        graphics.drawBitmap(
                Display.getWidth() - imagebitmap[index].getWidth() - 5,
                y + 3, imagebitmap[index].getWidth(),
                imagebitmap[index].getHeight(), imagebitmap[index], 0, 0);
        graphics.setColor(Color.WHITE);
        graphics.drawRect(0, y, width, imagebitmap[index].getHeight() + 10);



        graphics.setColor(Color.BLACK);
        graphics.setFont(Font.getDefault().derive(Font.BOLD, 20));
        graphics.drawText(title[index], 5, y + 3, 0, Display.getWidth()
                - imagebitmap[index].getWidth() - 10);

        System.out.println(Display.getWidth()
                - imagebitmap[index].getWidth() - 10);

        graphics.setColor(Color.GRAY);
        graphics.setFont(Font.getDefault().derive(Font.BOLD, 15));
        graphics.drawText(date[index], 5, y + 6
                + Font.getDefault().getHeight() + 3);

        if (islatest) {
            graphics.setColor(Color.RED);
            graphics.setFont(Font.getDefault().derive(Font.BOLD, 15));
            graphics.drawText(category[index], Font.getDefault()
                    .getAdvance(date[index]) + 3, y + 6
                    + Font.getDefault().getHeight() + 3);
        }
    }

    public Object get(ListField listField, int index) {
        return content.elementAt(index);
    }

    public int getPreferredWidth(ListField listField) {
        return Display.getWidth();
    }

    public int indexOfList(ListField listField, String prefix, int start) {
        return content.indexOf(prefix, start);
    }
}

public int getCurrentPosition() {
    return currentPosition;
}

protected boolean navigationClick(int status, int time) {
    int index = getCurrentPosition();
    if (catsid[index] == 9) {
        if (Config_GlobalFunction.isConnected()) {
            webpage = new BrowserField();
            listener = new Custom_BrowserFieldListener();
            webpage.addListener(listener);

            MainScreen aboutus = new Menu_Aboutus();
            aboutus.add(webpage);
            Main.getUiApplication().pushScreen(aboutus);

            webpage.requestContent("http://www.orientaldaily.com.my/index.php?option=com_k2&view=item&id="
                    + newsid[index] + ":&Itemid=223");
        } else
            Config_GlobalFunction.Message(Config_GlobalFunction.nowifi, 1);
    } else
        Main.getUiApplication().pushScreen(
                new Main_NewsDetail(newsid[index]));
    return true;
}
}

这篇关于无法分配定时器0:没有插槽左,无法设置动态的行高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆