Java/BlackBerry 构建错误覆盖太多类
有人听说过 Java 中重写过多的类吗?也许这个问题只与黑莓开发有关,但我想知道这是否也是Java中的问题。
假设我有以下内容:
LabelField lblTitle = new LabelField(title) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00FFFFFF);
graphics.clear();
super.paint(graphics);
}
};
LabelField lblSubTitle = new LabelField(releaseYear + ", " + rating) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00FFFFFF);
graphics.clear();
super.paint(graphics);
}
};
该代码有效。但是,我注意到,通过在整个项目中的许多不同类中多次重写 Paint() 方法,我收到了错误:
I/O Error: Cannot run program "jar": CreateProcess error=2, The system cannot find the file specified
到目前为止,我唯一的解决方案是清理我的 GUI 代码...最小化它并重用它。也许发生这种情况是件好事,这样我就可以在我的类中创建 GUI 代码时不再那么粗心了。
无论如何,我只是想知道以前是否有人听说过这个。如果您有兴趣阅读有关我遇到的问题的更多信息,请查看以下链接:
Has anyone ever heard of overriding too many classes in Java? Perhaps this issue is just related to BlackBerry development, but I was wondering if it is an issue in Java, too.
Let's say I have the following:
LabelField lblTitle = new LabelField(title) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00FFFFFF);
graphics.clear();
super.paint(graphics);
}
};
LabelField lblSubTitle = new LabelField(releaseYear + ", " + rating) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00FFFFFF);
graphics.clear();
super.paint(graphics);
}
};
This code works. However, I've noticed that by overriding the paint() method multiple times in many different classes throughout my project, I receive the error:
I/O Error: Cannot run program "jar": CreateProcess error=2, The system cannot find the file specified
My only solution thus far is to clean up my GUI code...minimize it and reuse it. Perhaps its good that this happened so I can be less careless about creating GUI code all over my classes.
Anyways, I was just wondering if anyone has heard of this before. If you are interested in reading more about the issue I have been facing, check out the following link:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您重写
paint()
的次数不太可能产生您报告的错误。该错误似乎是由于构建(编译)错误导致无法创建 jar。因此,您应该尝试仔细查看编译器/构建工具报告的错误消息。如果这不起作用,你可以尝试通过“分而治之”的方式来查找错误原因,如下:注释掉你重写
paint()
的所有地方。如果问题消失,请取消其中一半覆盖的注释,然后重试。如果问题再次出现,请评论这一半的一半(并继续递归)。否则,如果问题仍然存在,请注释第一半部分并取消注释第二半部分(并继续递归)。即使您在很多地方重写了paint(),这种类型的二分搜索也会很快收敛。例如,如果
paint()
被重写 256 次,则只需八次递归迭代即可找出导致问题的原因。It is unlikely that the number of times you override
paint()
yields the error you're reporting. It seems that the error is due to a build (compilation) error which prevents the jar from being created. You should therefore try and take a closer look at the error messages reported by your compiler/build tool.If this does not work, you can try to find the cause of the error by "divide and conquer", as follows: comment out all places where your override
paint()
. If the problem disappears, uncomment half of these overrides and try again. If the problem comes back comment half of this half (and continue recursively). Otherwise, If the problem is still gone, comment back the 1st half and uncomment the 2nd half (and continue recursively).Even if you have many places where you override
paint()
, this type of binary search will converge quite quickly. For example, ifpaint()
was overridden 256 times you only need eight recursive iterations to find out the one that is causing the problem.