Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 绘制一个列表字段,并基于解析XML文件信息的向量在屏幕上绘制图形_Java_Xml_Graphics_Blackberry_Listfield - Fatal编程技术网

Java 绘制一个列表字段,并基于解析XML文件信息的向量在屏幕上绘制图形

Java 绘制一个列表字段,并基于解析XML文件信息的向量在屏幕上绘制图形,java,xml,graphics,blackberry,listfield,Java,Xml,Graphics,Blackberry,Listfield,程序正确地符合要求,但当它在模拟器8800中运行时,当执行此代码时,它会崩溃 此代码是问题的根源: public class CategoriesUI extends MainScreen implements ListFieldCallback { //categoryimport.listingnodup is the current categories with no duplicates public Categories categoryimport = ne

程序正确地符合要求,但当它在模拟器8800中运行时,当执行此代码时,它会崩溃

此代码是问题的根源:

   public class CategoriesUI extends MainScreen implements ListFieldCallback {

    //categoryimport.listingnodup is the current categories with no duplicates
    public Categories categoryimport = new Categories(); //brings in all infromation from Categories.java

    private ListField allcategories;

    CategoriesUI() {     

        this.add(new LabelField("List of Categories"));
        allcategories = new ListField(categoryimport.listingnodup.size());
        allcategories.setCallback(this); //we manage the interaction!
        this.add(allcategories);

    }

    protected boolean onSavePrompt() {

        return true;
    }


    //Implemented Call Back Methods follow

    //draw the current row
    public void drawListRow(ListField list, Graphics g, int index, int y, int w) {

        catdrawer categorydraw = (catdrawer) this.get(list, index);
        int drawColor = Color.BLACK;
        g.setColor(drawColor);
        g.drawText(categorydraw.cat, 0, y, 0, w);

    }

    public int getPreferredWidth(ListField list) {

        return Display.getWidth();

    }   

    public int indexOfList(ListField listField, String prefix, int start) {

        //Not a current implementation this is really just commented out
        return start;

    }

    //Returns the object at the specified index
    public Object get(ListField list, int index){

        return categoryimport.listingnodup.elementAt(index);

    }

    class catdrawer {

        public String cat = categoryimport.listingnodup.toString(); 

    }    
    }

当categorydraw为null时,稍后对drawtext 3行的调用将引发异常。您需要检查空值。

它是如何崩溃的?它是否生成堆栈跟踪?你可能想把它包括进去。。。什么是模拟器8800?模拟器8800是指模拟黑莓8800的黑莓模拟器。
catdrawer categorydraw = (catdrawer) this.get(list, index);