Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Adobe AIR Development

Reply
Developer
T55555
Posts: 117
Registered: ‎12-03-2010

application termine without any error ?!

Hi,

 

When I tested on my app on simulator, sometime, it exits "by itself".

My code did not have any close() window or any exit code.

 

This seems bugs, but on debug mode, I don't see any error message ...

My app should very small, so, I don't think any memory low and system force exit issue.

 

Does anyone have such problem too?  ( How to debug ? )

 

Thanks,

 

Please use plain text.
Developer
jtegen
Posts: 6,154
Registered: ‎10-27-2010
My Carrier: AT&T

Re: application termine without any error ?!

It is most likely crashing in the simulator.  See if you can reproduce the runtime error in AIR which will give verbose error messages.  If it only seems to occur on the simulator, there are lots of threads in this forum that covers how to run your application in the simulator with remote debug back to your local computer that will show trace information and hopefully when an exception is thrown.

Please use plain text.
Developer
T55555
Posts: 117
Registered: ‎12-03-2010

Re: application termine without any error ?!

I actually added throw error code on my app to force it crash for testing, and I did see the debug mode work very well to report my testing error.

 

The situation now is, it "crash?" on debug mode and without any error back to my local computer...

( which seems no any exception happend and it is just "crash" and exit )

Please use plain text.
Developer
T55555
Posts: 117
Registered: ‎12-03-2010

Re: application termine without any error ?!

This is drving me crazy... I think that it is related to event  stuff.

In fact, instead of each object has its own custom event. I create a EventCenter.

All events is dispatch via EventCenter, and all views are listener via EventCenter too.

In this way, all objects are independent and loose couple.

 

Since I am newbis on event stuff. I am not 100% sure the code is correct or not.

( it may related to the strange "crash" without exception ?? )

 

Please let me know if you find any problem on below code.

 

Thank you for your help.

 

 

	import flash.events.Event;
	import flash.events.EventDispatcher;

	public class EventCenter
	{
		private static var eventDispatcher:EventDispatcher = new EventDispatcher();
		
		public static function dispatchEvent(event:Event):Boolean
		{
			return eventDispatcher.dispatchEvent(event);
		}
		
		public static function addEventListener(type:String, listener:Function):void
		{
			eventDispatcher.addEventListener(type, listener);
		}
		
		public static function removeEventListener(type:String, listener:Function):void
		{
			eventDispatcher.removeEventListener(type, listener)
		}		
	}

 

 

Please use plain text.
Developer
jtegen
Posts: 6,154
Registered: ‎10-27-2010
My Carrier: AT&T

Re: application termine without any error ?!

How are all your objects and views accessing this class?  Is it instantiated just once in your application?  Are you using it as a singleton or used within a singleton?

 

I guess if you want a single path way, I would extend EventDispatcher to EventCenter and have it as a singleton.  But you might have something else in mind for this.

Please use plain text.
Developer
T55555
Posts: 117
Registered: ‎12-03-2010

Re: application termine without any error ?!

all my object are use its static method and never instance it.

 

I will try your suggestion... base on your suggestion, the code will be like....

 

public class EventCenter extends EventDispatcher {

   private static var _instance:EventCenter = new EventCenter();

 

  public static get function instance():EventCenter { return _instance; }

 

 

And all object will access via like  :  EventCenter.instance.addListener ( removeListener, dispatchEvent ... etc)

 

Is that your thinking to implement singleton EventCenter ?

 

Thanks.

Please use plain text.
Developer
T55555
Posts: 117
Registered: ‎12-03-2010

Re: application termine without any error ?!

base on your suggestion, my new code is like ....

 

	import flash.events.EventDispatcher;

	public class EventCenter extends EventDispatcher
	{
		private static const _instance:EventCenter = new EventCenter();
		
		public static get function instance():EventCenter
		{
			return _instance;
		}
	}

 

 

Please use plain text.
Developer
jtegen
Posts: 6,154
Registered: ‎10-27-2010
My Carrier: AT&T

Re: application termine without any error ?!

Yes, that is what I had in mind, but does that help the termination issue?  Or is it something else?

Please use plain text.
Developer
jtegen
Posts: 6,154
Registered: ‎10-27-2010
My Carrier: AT&T

Re: application termine without any error ?!

I believe your instance method should look like this:

 

 

//////////////////////////////////////////////////////////////////////////
    public static function get instance() : EventCenter
{ if( _instance == null ) // first time { _instance = new EventCenter(); } return _instance; }

 But your method might work too.  I'm just use in doing this way.

 

Please use plain text.
Developer
T55555
Posts: 117
Registered: ‎12-03-2010

Re: application termine without any error ?!

Hi jtegen,

I think that I "found" the problem; the problem is not on EventCenter.

The problem may on the persistence data stuff ( which I think that I copied your code from some discussion thread...,  ).

The persistence is using simple xml data like code below.

The persistence works fine, it did save and load back data.

But, I think they may also related to terminate issue.

When I comment out the content of save() and load()... No more terminate issue....

I still cannot find out what's wrong on save() and load().

 

 

public function save():void
{
	var fileStream:FileStream = new FileStream();
	try 
	{
		var file:File = File.applicationStorageDirectory.resolvePath(CONFIG_FILE_NAME);			
		fileStream.open(file, FileMode.WRITE);
		var output:String = '<?xml version="1.0" encoding="utf-8"?>' + File.lineEnding;
		output += '<config>' + File.lineEnding;
		output += '<my_data>' + some_data + '</my_data>' + File.lineEnding;
		output += '</config>' + File.lineEnding;
		trace( "save-output=" + output );
		fileStream.writeUTFBytes(output);
	} 
	finally 
	{
		try { fileStream.close(); } catch (error:*) { trace(error); }
	}
}

public function load():void
{
	var file:File = File.applicationStorageDirectory.resolvePath(CONFIG_FILE_NAME);
	if( file.exists ) {
		var fileStream:FileStream = new FileStream();
		try 
		{
			fileStream.open(file, FileMode.READ);
			var config:XML = new XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
			if (config.hasOwnProperty('my_data'))
			{
				restore(config.my_data);
			}
			trace( "load-input=" + config.toString() );
		} 
		finally 
		{
			try { fileStream.close(); } catch(error:*) { trace(error); }
		}
	}
}

 

 

Please use plain text.