1

I define a enum named SexType, and want use as the following:

public class People {
    //@Property("copy, nonatomic") protected String location;
   // @Property("copy, nonatomic") protected SexType sex;
   public String name;
   public SexType sex;
   public People(String name){
     this.name = name;
  }

  public String say(String text){
        return this.name + " say:" + text;
  }

public void setName(String name){
    this.name = name;
}

}

It run ok in java side, but it failed when translate to objC and error is "SexType cannot be resolved to a type". Who know the reason?

Thanks

Leo
  • 835
  • 1
  • 12
  • 31

1 Answers1

1

j2objc is a Java compiler (it uses Eclipse's JDT as its front-end), and requires the same path flags as javac. Since "class cannot be resolved to a type" is a Java compiler error, that means it's likely that the -sourcepath flag is incorrect, since that's how Java compilers locate types in other Java source files.

The quick way to verify correct source and class path in a j2objc command line is to use those same flags in a javac command, fix any compilation errors, then use those same paths in the j2objc command. To see what command Xcode is failing with, put an "echo " in front of the j2objc command in its build rule, build the app, and then expand the "Run shell script build rule on ..." log entry to see the command.

The second line of the command log has a "cd " command, open a terminal window and run that line so you are in the working directory Xcode uses. Type javac -sourcepath ../../j2ObjcDemon_SharedLib/src/main and the path to either or both Java sources. Fix the source path until javac can compile those files, then use the fixed path in the j2objc build rule.

tball
  • 1,984
  • 11
  • 21
  • I have done as the above steps,but it still failed in the path where javac can compile – Leo Jun 01 '16 at 14:36
  • j2objc is an advanced software engineering tool, and requires knowledge of Java, iOS, and command-line software development experience. If you are new to Java development, using j2objc is not recommended. – tball Jun 04 '16 at 13:38