tags:

views:

322

answers:

3

I'm a Java programmer and i wanted to get into writing so apps for the Iphone. I started to research and found myself looking at xmlvm..that all good, but then xmlvm has a HelloWorld.java with some UIWindow classes that i can't find and can't compile. Short of it is where is the api for Java so i can compile xmlvm's HelloWorld.java for the Iphone. Here's the code: and i've already compiled xmlvm with ant and have xmlvm.jar in my classpath so??

import org.xmlvm.iphone.*;

public class HelloWorld extends UIApplication {

    public void applicationDidFinishLaunching(UIApplication app) {
        UIScreen screen = UIScreen.mainScreen();
        CGRect rect = screen.applicationFrame();
        UIWindow window = new UIWindow(rect);

        rect.origin.x = rect.origin.y = 0;
        UIView mainView = new UIView(rect);
        window.addSubview(mainView);

        UILabel title = new UILabel(rect);
        title.setText("Hello World!");
        title.setTextAlignment(UITextAlignment.UITextAlignmentCenter);
        mainView.addSubview(title);

        window.makeKeyAndVisible();
    }

    public static void main(String[] args) {
        UIApplication.main(args, HelloWorld.class);
    }

}
+3  A: 

There is no java VM on the iphone - xmlvm must cross-compile the java code into an executable for the phone.

edit 1: that said coming from Java, you may not find objective-C that much of a shock to migrate to. It took me a few months to learn it coming from Java and C/C++ - most of the books about iphone programming (e.g. the pragmatic programmer's one) also give a little background on the language to get you started. It is a learning curve but ultimately I suspect a lot less frustrating as it the first-class language on the phone and well supported by tools and documentation etc.

edit 2: From a glance at the webpage, it looks like what xmlvm produces is actually objective-C, linked against a native xvmlm support framework. I assume the next step is to compile the objective-C output using whatever toolchain you have - probably xcode but if not then some gcc toolchain. Anyway the end result is going to be a native executable not java bytecode. You'll install that just like any executable you build from objective-C.

frankodwyer
I did it the other way around and found learning Java quite easy because I was using Obj-C. Of course I was also familiar with C++ which helped with the syntax.
Robin
A: 

Looks like this question was posted 5 months ago, so it might be too late - but I imported this HelloWorld.java file into NetBeans and then added the xmlvm.jar to my library path - soon to see that

CGRect rect = screen.applicationFrame();

and

title.setTextAlignment(UITextAlignment.UITextAlignmentCenter);

Were broken. Thankfully, NetBeans' auto-complete told me to change the first to

CGRect rect = screen.getApplicationFrame();

and the second to:

title.setTextAlignment(UITextAlignment.Center);

I then proceeded to compile the NetBeans project without error. xmlvm compiled my resulting byte-code (.class files) to an iPhone/XCode app but then I could not get THAT to compile because of inconsistencies in the automatically generated code.

XMLVM looks like a great project which is very promising, but as they keep updating their code, their documentation's falling behind resulting in the first mishap.

I have no logical explanation to the second.

Warlax
A: 

I know this isn't exactly what you asked, but you might have a look at the GWT. It makes your app web based (which keeps it out of the store, and therefore most people aren't interested because they can't make that sweet iStore cash) but it allows you to program for web clients in a very natural java language--you can avoid dealing with "Web" protocols altogether if you so choose.

Bill K