|
From: Panayotis K. <pan...@pa...> - 2011-07-07 14:30:08
|
What do you think about the solution for this specific problem?
Use the following code for the selector applicationDidFinishLaunching of UIApplicationDelegate
- (void) applicationDidFinishLaunching: (UIApplication*) app
{
SEL selector = NSSelectorFromString([NSString stringWithFormat:@"__init_%s__", class_getName([self class])]);
[self performSelector:selector];
[self applicationDidFinishLaunching___org_xmlvm_iphone_UIApplication: app];
}
As a side note, probably we should do the same for the UIApplication object as well (if it is an instance of org_xmlvm_iphone_UIApplication)
On 11 Νοε 2010, at 6:56 μ.μ., Arno Puder wrote:
>
> that is a known issue. The code that XMLVM generates is correct. The
> problem is that certain classes (such as UIAppication*) are instantiated
> by Cocoa and Cocoa doesn't know about the __init__*() constructors that
> were generated by XMLVM. The initialization of 'test' in your example
> will end up in the default constructor for class Main and since Cocoa
> doesn't call it, it won't get initialized.
>
> This will work perfectly fine for any other class (that is handled by
> XMLVM). It is just this special case when Cocoa instantiates a Java
> object. Back then I couldn't think of a solution for this. I'll revisit
> this with the C backend. Here we might have more hooks to solve this
> problem.
>
> Arno
>
>
> On 11/11/10 7:08 AM, Panayotis Katsaloulis wrote:
>> there is something missing when variables are initialized outsize the constructor.
>>
>> As a minium program to display this error, have a look at this: instead of printing "hello", it prints "null", since this is not initialized.
>>
>>
>>
>>
>> package my.testmem;
>>
>> import org.xmlvm.iphone.UIApplication;
>> import org.xmlvm.iphone.UIApplicationDelegate;
>>
>> public class Main extends UIApplicationDelegate {
>>
>> String test = "hello";
>>
>> @Override
>> public void applicationDidFinishLaunching(UIApplication app) {
>> System.out.println(test);
>> }
>>
>> public static void main(String[] args) {
>> UIApplication.main(args, null, Main.class);
>> }
>> }
|