1

Eclipse 不断告诉我调用问题。这是我收到的消息,如下所示。请帮我解决这个问题。我应该放什么代码来摆脱调用问题。谢谢。

Warning!: method 'parsepack.xmlparsing.navigationClick(int,int)' not invoked.
Warning!: method 'parsepack.xmlparsing.insert(String,int)' not invoked.

这是方法navigationClick()

protected boolean navigationClick(int status, int time)
{
    try
    {
        //navigate here to another screen   
        ui.pushScreen(new ResultScreen()); 
    }
    catch(Exception e)
    {
       System.out.println("Exception:-  : navigationClick() "+e.toString());
    }
    return true;
}

这是方法insert()

public void insert(String toInsert, int index) 
{
    listElements.addElement(toInsert);
}

这是类xmlparsing.java

package parsepack;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.xml.parsers.DocumentBuilder;
import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class xmlparsing extends UiApplication implements ListFieldCallback, FieldChangeListener
{

    public static void main(String[] args)
    {
        xmlparsing app = new xmlparsing();
        app.enterEventDispatcher();
    }


    public long mycolor ;
    Connection _connectionthread;
    private static ListField _list;
    private static Vector listElements = new Vector();
    public MainScreen screen = new MainScreen();
    VerticalFieldManager mainManager;
    VerticalFieldManager subManager;
    UiApplication ui = UiApplication.getUiApplication();


    public  xmlparsing()
    {
        super();
        pushScreen(screen);

        final Bitmap backgroundBitmap = Bitmap.getBitmapResource("blackbackground.png");

        mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR )
        {

            public void paint(Graphics graphics)
            {
                graphics.drawBitmap(0, 0, Display.getWidth(),Display.getHeight(),backgroundBitmap, 0, 0);

                super.paint(graphics);
            }

        };

        subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR )
        {
            protected void sublayout( int maxWidth, int maxHeight )
            {
                int displayWidth = Display.getWidth();
                int displayHeight = Display.getHeight();

                super.sublayout( displayWidth, displayHeight);
                setExtent( displayWidth, displayHeight);
            }
        };


        screen.add(mainManager);

        _list = new ListField()

        {

            public void paint(Graphics graphics)

            {
                graphics.setColor((int) mycolor);
                super.paint(graphics);

            }

        };
        mycolor = 0x00FFFFFF;
        _list.invalidate();
        _list.setEmptyString("* Feeds Not Available *", DrawStyle.HCENTER);
        _list.setRowHeight(50);
        _list.setCallback(this);
        mainManager.add(subManager);
        listElements.removeAllElements();
        _connectionthread = new Connection();
        _connectionthread.start();
    }


    protected boolean navigationClick(int status, int time)
    {
        try
        {
            //navigate here to another screen
            ui.pushScreen(new ResultScreen());                
        }
        catch(Exception e)
        {
            System.out.println("Exception:-  : navigationClick() "+e.toString());                
        }

        return true;
    }



    private class Connection extends Thread
    {
        public Connection()
        {
            super();
        }

        public void run() {
            Document doc;
            StreamConnection conn = null;
            InputStream is = null;
            try {

                conn = (StreamConnection) Connector.open("http://imforchange.org/international-movement-for-change/testing/data.xml"+";deviceside=true");

                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                docBuilderFactory.setIgnoringElementContentWhitespace(true);
                docBuilderFactory.setCoalescing(true);
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                docBuilder.isValidating();
                is = conn.openInputStream();
                doc = docBuilder.parse(is);
                doc.getDocumentElement().normalize();
                NodeList list = doc.getElementsByTagName("eventName");
                for (int i = 0; i < list.getLength(); i++)
                {
                    Node textNode = list.item(i).getFirstChild();
                    listElements.addElement(textNode.getNodeValue());
                }

            } catch (Exception e) {
                System.out.println(e.toString());
            } finally {
                if (is != null) {
                    try { 
                        is.close();
                    } catch (IOException ignored) {
                    }
                }
                if (conn != null) {
                    try { 
                        conn.close(); 
                    }
                    catch (IOException ignored) {
                    }
                }    
            } 
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    _list.setSize(listElements.size());
                    subManager.add(_list);
                    screen.invalidate();
                }
            });
        }

    }


    public void drawListRow(ListField list, Graphics g, int index, int y, int w)
    {
        String tes = (String)listElements.elementAt(index);
        int yPos = 0+y;
        g.drawLine(0, yPos, w, yPos);
        g.drawText(tes, 5, 15+y, 0, w);
    }


    public Object get(ListField list, int index)
    {
        return listElements.elementAt(index);
    }
    public int indexOfList(ListField list, String prefix, int string)
    {
        return listElements.indexOf(prefix, string);
    }
    public int getPreferredWidth(ListField list)
    {
        return Display.getWidth();
    }
    public void insert(String toInsert, int index) {
        listElements.addElement(toInsert);
    }

    public void fieldChanged(Field field, int context) {


    }
}

ResultScreen.java

package parsepack;

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public class ResultScreen extends MainScreen {

    public ResultScreen() {
        LabelField resultLabel = new LabelField("Result: ");  
        add(resultLabel);
    }  

}
4

1 回答 1

1

首先,您看到的那些消息是警告,而不是错误。警告并不总是一个问题,但有时确实如此。在这种情况下,我认为至少第一条消息是有问题的,因此您需要修复它。

1)一是navigationClick()方法。编译器告诉您,您有一个navigationClick()永远不会从您的任何代码或 BlackBerry OS 基础架构调用的方法的实现。这可能不是你想要的。通常,navigationClick()它是您在编写extends的 BlackBerryField类之一的类中覆盖的方法。例如,ButtonField子类。 navigationClick()在这种情况下,将在单击按钮时调用。

但是,您将navigationClick()方法放在UIApplication主子类中。那不是你想要的。您需要该方法到override字段navigationClick()类中的方法。我不确定当用户单击时您希望哪个字段调用此方法。但是,例如,您可能会执行以下操作:

_list = new ListField()
{
    public void paint(Graphics graphics)
    {
        graphics.setColor((int) mycolor);
        super.paint(graphics);
    }
    protected boolean navigationClick(int status, int time)
    {
        try
        {
            //navigate here to another screen
            ui.pushScreen(new ResultScreen());
        }
        catch(Exception e)
        {
            System.out.println("Exception:-  : navigationClick() "+e.toString());
        }
        return true;
    }
}; 

当你的列表被点击时,这会navigationClick()被调用,它会摆脱警告。

2)关于警告insert(),那只是因为你没有在任何地方使用它。看起来您已经添加了该方法以允许xmlparsing类外部的代码能够将项目插入列表中。也许这就是您想要的,但是您还没有编写其他代码来使用该方法。我看到你至少有几个选择:

  1. 删除或注释掉该insert()方法,直到您需要它为止。这将摆脱警告。
  2. 添加更多使用此方法的代码。
  3. 忽略警告,只需确保您了解警告告诉您您有一些(还)不需要的代码,因为它未使用
  4. 如果您知道警告不是问题,并且您不希望过多的警告隐藏实际问题,则可以通过在 Eclipse 首选项中执行此操作或此操作来抑制 Java 程序中的警告。我通常不推荐这个。通常,最好修复警告,而不是隐藏它。
于 2012-10-11T21:06:00.113 回答