将一些处理代码移植到 Eclipse,出现大量错误
我正在使用Processing 制作一个Android 应用程序,并决定将我的代码移植到Eclipse。我猜想处理和纯 Java 之间有很多区别,因为我立刻就遇到了对我来说毫无意义的错误。例如:
int inactiveThreshold = 300 + int(random(-100, 100));
int randomPointInterval = int(random(300, 500));
我收到错误“令牌“int”上的语法错误,删除此令牌”
至于随机函数,我扩展了 PApplet 并导入了processing.core.*,所以我不明白为什么它不能正常工作。
在引用我创建的颜色的任何内容上也会出现错误:
back.drawBackground("shadow", backgroundColor);
back.drawBackground("front", backgroundColor);
“颜色无法解析为类型”,尽管将backgroundColor初始化为整数:
int backgroundColor = color(100, 100, 120);
主类中还有一个处理鼠标移动的函数,当我引用它时表示该函数未定义。
这些错误只是在主类中,所以我认为我应该先解决这个问题。我主要遵循这个来移植代码:
http://www.learningprocessing。 com/tutorials/processing-in-eclipse/
我没有在纯 Java 中做太多事情,所以处理的预编译器处理的可能有很多我没有注意到的差异。
I'm making an Android app using Processing, and have decided to port my code to Eclipse. I guess there are a lot of differences between Processing and pure Java, because right off the bat I am getting errors that make little sense to me. For example:
int inactiveThreshold = 300 + int(random(-100, 100));
int randomPointInterval = int(random(300, 500));
I get the error "Syntax error on token "int", delete this token"
As for the random function, I extend PApplet and have imported processing.core.* so I don't see why that wouldn't work properly.
Also getting errors on anything referencing a color that I created:
back.drawBackground("shadow", backgroundColor);
back.drawBackground("front", backgroundColor);
"Color cannot be resolved to a type", despite initializing backgroundColor as an integer:
int backgroundColor = color(100, 100, 120);
There's also a function in the main class that handles mouse movement, and when I make a reference to it says that the function is undefined.
These errors are just in the main class, so I figured I should tackle that before anything else. I've mainly been following this for porting the code:
http://www.learningprocessing.com/tutorials/processing-in-eclipse/
I haven't done much in pure Java so there are probably a lot of differences that Processing's precompiler handles that I'm not noticing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 int 转换: do
对于随机数:
任何时候看到 java.blah.ClassName,都可以执行此操作,这样它就不会与 java.blah 限定符混淆。
For int casting: do
For randoms:
Any time you see java.blah.ClassName, you can do this so it's not cluttered with java.blah qualifiers.
老实说,如果它运作得很好,我会感到惊讶。处理未优化的屏幕设备,这会给您带来一些问题。据我了解,它运行在 JVM 之上的 Java 虚拟机上。这与在 Android 中使用的 Dalvik VM 上运行有很大不同。
然而,似乎有相当多的人支持它。我会直接检查该社区。 http://wiki.processing.org/w/Android
I would be surprised if it works very well to be honest. Processing is not optimized screen devices and that will cause you some problems. Also far as I understand it runs on the Java virtual machine on top of the JVM. This is quite different from running on top of the Dalvik VM that is used in Android.
However there seems to be quite a bit of support for it. I would check that community directly. http://wiki.processing.org/w/Android
事实证明,有一个关于如何让处理应用程序在纯 Java 环境中运行的很好的教程(假设这就是您想要的): http://processing.org/learning/eclipse/
简而言之,您:
然后将对 PApplet 的引用传递到您想要使用“本机”处理函数的任何类中。这样,您之前所说的:
您现在可以说:
我还应该提到这里有一个活跃的 Adroid 处理论坛: https://forum.processing.org/android-processing——那里有人已经走上了这条路。
Turns out there's a nice tutorial on how to get a Processing app to run in a pure Java environment (assuming that's what you want): http://processing.org/learning/eclipse/
In short, you:
then pass a reference to PApplet into any classes where you want to use "native" processing functions. That way, where you previously said:
you can now say:
I should also mention there's an active Adroid processing forum here: https://forum.processing.org/android-processing -- there are people there who have already gone down this road.