-1

我正在尝试使用 J2Objc 将 Java 中 Unicode 实现的压缩方案转换为 Objective-C。我已经成功下载并编译了 J2Objc 并./j2objec /SCSU/*.java在确保 Java 代码编译后运行该命令。尽管如此,我还是遇到了一大堆错误,主要是说某些类、变量和函数是未定义的:

error: SCSU/Compress.java:41: SCSU cannot be resolved to a type
error: SCSU/Compress.java:63: The method getCurrentWindow() is undefined for the type Compress
error: SCSU/Compress.java:77: The method selectWindow(int) is undefined for the type Compress
error: SCSU/Compress.java:105: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:105: EndOfInputException cannot be resolved to a type
error: SCSU/Compress.java:105: IllegalInputException cannot be resolved to a type
error: SCSU/Compress.java:107: The method getCurrentWindow() is undefined for the type Compress
error: SCSU/Compress.java:126: IllegalInputException cannot be resolved to a type
error: SCSU/Compress.java:134: EndOfInputException cannot be resolved to a type
error: SCSU/Compress.java:143: IllegalInputException cannot be resolved to a type
error: SCSU/Compress.java:165: SQ0 cannot be resolved to a variable
error: SCSU/Compress.java:171: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:171: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:173: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:181: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:216: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:218: Debug cannot be resolved
error: SCSU/Compress.java:219: The method getCurrentWindow() is undefined for the type Compress
error: SCSU/Compress.java:224: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:228: SQ0 cannot be resolved to a variable    
error: SCSU/Compress.java:231: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:231: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:233: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:238: staticOffset cannot be resolved to a variable
error: SCSU/Compress.java:238: staticOffset cannot be resolved to a variable
error: SCSU/Compress.java:240: staticOffset cannot be resolved to a variable
error: SCSU/Compress.java:245: Assert cannot be resolved to a type
error: SCSU/Compress.java:249: Debug cannot be resolved
error: SCSU/Compress.java:266: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:279: The method isCompressible(char) is undefined for the type Compress

日志继续...为什么我会收到这样的错误,我应该怎么做才能解决它们?

4

1 回答 1

1

您需要在 -sourcepath 中指定源代码所在的目录(j2objc 使用 Eclipse 编译器作为其前端,这就是此要求的来源)。我将这些源文件复制到 ~/Downloads/unicode,并使用以下命令:

$ j2objc -d build -sourcepath ~/Downloads/unicode ~/Downloads/unicode/*.java translating /Users/tball/Downloads/unicode/Assert.java translating /Users/tball/Downloads/unicode/Compress.java translating /Users/tball/Downloads/unicode/CompressMain.java translating /Users/tball/Downloads/unicode/Debug.java translating /Users/tball/Downloads/unicode/Display.java translating /Users/tball/Downloads/unicode/EndOfInputException.java translating /Users/tball/Downloads/unicode/EndOfOutputException.java translating /Users/tball/Downloads/unicode/Expand.java translating /Users/tball/Downloads/unicode/IllegalInputException.java error: /Users/tball/Downloads/unicode/SCSU.java:241: The method reset in type SCSU can only set one of public / protected / private

最后这是一个奇怪的错误,但查看源代码发现它确实是非法的 Java:

SCSU.java:241: protected public void reset() { ...

修复它(删除任一修饰符),你应该很高兴。

于 2015-06-03T23:00:29.077 回答