黑莓导航单击调用问题



Eclipse不断告诉我调用问题。这是我收到的信息,如下所示。请帮我解决这个问题。我应该放入哪些代码来解决invoke问题。谢谢

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

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

1) 首先,navigationClick()方法。编译器告诉您,方法navigationClick()的实现从未从任何代码或BlackBerry操作系统基础结构调用过。这可能不是你想要的。通常,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. 如果您知道警告不是问题,并且不希望过多的警告隐藏真正的问题,那么您可以在Java程序中通过在Eclipse首选项中这样做或这样做来抑制警告。我通常不建议这样做。通常,与其隐藏警告,不如修复警告

相关内容

  • 没有找到相关文章

最新更新