Alternative Methods in codenameone

流过昼夜 提交于 2019-12-06 09:13:49
ChiefTwoPencils

I can't say for sure about all the examples you provided but you should consider looking into the CN1 API Javadocs for information on how to do it "their way".

For example, when it comes to File, the Javadocs say:

The main reason java.io.File & java.io.FileInputStream weren't supported directly has a lot to do with the richness of those two API's. They effectively allow saving a file anywhere, however mobile devices are far more restrictive and don't allow apps to see/modify files that are owned by other apps.

So, the answer to that one is, use theirs. Similarly, search the CN1 Javadocs to learn the appropriate ways to do what you need using their APIs.

You can also refer to the developer guide e.g. most file based operations should be performed either thru Storage or FileSystemStorage both of which are covered here. You should be very careful with code that uses java.io.File as this might rely on desktop specific behaviors.

FileNotFoundException can be replaced with IOException (it's a subclass of IOException anyway).

There is no direct equivalent to Scanner but there are builtin parsers for JSON, XML, CSV & Properties.

Some of the math functions are in MathUtil that includes Math.pow(double, double).

There is no equivalent to the format() method of Java SE. You would need to concatenate strings instead.

Notice that if you post some code as a question we can sometimes help with the Codename One equivalent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!