1

Eclipse keeps telling me about invoke problems. This is the message i get as can be seen below. Please help me resolve this problem. What code should i put to get rid of the invoke problem. thanks.

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

here is the method 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;
}

here is the method insert()

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

here is the class 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);
    }  

}
Nate
  • 31,017
  • 13
  • 83
  • 207
ejobity
  • 305
  • 1
  • 3
  • 13
  • Is there any button or some UI on which you are calling `navigationOnClick()` method. – BBdev Oct 11 '12 at 04:34
  • where you are using this navigation click method? – Aman Arora BB Oct 11 '12 at 08:16
  • Can you just post your xmlparsing class here? I don't really want to download a RAR file to look at this. Thanks. – Nate Oct 11 '12 at 09:41
  • i updated it, i put the entire class here. thanks guys for wanting to help. :-) – ejobity Oct 11 '12 at 16:59
  • No problem. For future reference, you should probably check out [Jon Skeet's blog post on tips for asking questions](http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx). Also, remember that if you get an answer that helps you, or solves your problem, click on the arrow and/or checkmark next to it, to say that the suggestion helped, or that your problem is solved (or both). Thanks. – Nate Oct 11 '12 at 21:10

1 Answers1

1

First of all, those messages you're seeing are warnings, not errors. Warnings are not always a problem, but sometimes they are. In this case, I think that at least the first message is a problem, so you'll want to fix it.

1) First, the navigationClick() method. The compiler is telling you that you have an implementation for the method navigationClick() that is never called from any of your code, or by the BlackBerry OS infrastructure. That's probably not what you want. Normally, navigationClick() is a method that you override in a class you write that extends one of the BlackBerry Field classes. For example, a ButtonField subclass. navigationClick() will be called, in that case, when the button is clicked.

But, you placed your navigationClick() method in the main UIApplication subclass. That's not what you want. You need that method to override the navigationClick() method in a field class. I'm not sure which field you want to have call this method when the user clicks. But, for example, you might do something like this:

_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;
    }
}; 

That would make navigationClick() get called when your list is clicked, and it will get rid of the warning.

2) Regarding the warning about insert(), that's just because you're not using it anywhere. It look like you've added that method to allow code outside the xmlparsing class to be able to insert items into the list. Maybe that's what you want, but you just haven't yet written the other code to use that method. I see you having at least a few choices:

  1. remove or comment out the insert() method until you need it. this will get rid of the warning.
  2. add some more code that does use this method.
  3. ignore the warning, just making sure you understand that the warning is telling you that you have some code that is not (yet) necessary, since it's unused
  4. you can suppress warnings in Java programs, by doing this, or this, in the Eclipse preferences, if you know the warning is not a problem, and you don't want excessive warnings to hide real problems. I normally don't recommend this. Usually, it's better to fix the warning, than to hide it.
Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • wow. what a beautifully expressed answer. you are blessed. thanks alottt nate. i'll try it and give u feedback. – ejobity Oct 12 '12 at 01:55
  • @ejobity, happy to help. Thanks for posting your code, and describing your problem well. – Nate Oct 12 '12 at 02:46