Using methods in other class fails

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Leonos007
Posts: 2
Joined: 13 Sep 2021, 14:15

Using methods in other class fails

Postby Leonos007 » 13 Sep 2021, 14:37

I'm struggling very much with using different classes.
(RequestHandler classes are no problem, so that is not my issue)

I went back to a very simple code (to test) and it also fails.

I have created a helloExtension class which is loaded in Smartfox as mainClass.
Then I have a second helloWorld class in the same jar file.
(so one compiled jar file blaExtension with two classes, helloExtension and helloWorld)

Calling the first method test1 works without problem, but when I call the test2, I get java.lang.NullPointerException.
I cannot figure out why this is happening.
It looks like when using plain java code, there is no problem, but when I go use some Smartfox stuff in the second class, it fails.

My test code:

my extension class looks like this:

Code: Select all

public class helloExtension extends SFSExtension {
  HelloWorld bla = new HelloWorld();
  trace(bla.test1());
  bla.test2();
}


Then the second class helloWorld:

Code: Select all

class HelloWorld extends BaseClientRequestHandler {
  public String test1(){
       return("test1");
    }
  public void test2(){
       trace("test2");
    }
}


What can I do to use separate classes or is it impossible to call other methods from the mainClass ?
User avatar
Lapo
Site Admin
Posts: 22157
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Using methods in other class fails

Postby Lapo » 14 Sep 2021, 09:27

Hi,
if you get a NullPointer exception, check the stack trace of the error and see where exactly the NPE is raised.
Does it crash in your code? Or somewhere else? If the latter can you show us the full stack trace?

As a side note, from a purely "philosophical" standpoint you would normally not need to call a RequestHandler directly from the main Extension. I mean, you can actually do whatever you want :) But it doesn't look like a good idea from a logical point of view: RequestHandlers are classes that handle calls from clients, they are not supposed to expose methods that can be invoked internally.

It seems to me like there's a bit of a "design problem" in how you're structuring the code. Let us know what you're trying to do and we'll suggest a different way, if possible.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Leonos007
Posts: 2
Joined: 13 Sep 2021, 14:15

Re: Using methods in other class fails

Postby Leonos007 » 15 Sep 2021, 08:14

Hi Lapo,

I will redesign the part where I needed to call the class from the handler.

You are right that its purpose is not to do things like that, but I just went into tunnel vision trying to get it to work :)

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 25 guests