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.

inside custom component

Adobe AIR Development

Reply
Contributor
Posts: 19
Registered: ‎03-11-2012
My Device: Pearl 3G
My Carrier: Vodafone

Getting Error when running ANE app with parameters

[ Edited ]

Hello All,

 

I have a simple application which adds 2 number using ANE native methods.

 

I am getting the exception:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.math::MathLibrary/sayHello()[C:\FlashBuilder_ws\MathLibrary\src\com\math\MathLibrary.as:16]
at UsingMath2/onHelloButtonClick()[C:\FlashBuilder_ws\UsingMath2\src\UsingMath2.as:62]

 

Below is the code for the same

Native Side:

#include "FlashRuntimeExtensions.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void ExtensionInitializer(void** extDataToSet,
		FREContextInitializer* ctxInitializerToSet,
		FREContextFinalizer* ctxFinalizerToSet);
void ExtensionFinalizer();

void ContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
		uint32_t* numFunctionsToSet, const FRENamedFunction** functionsToSet);
void ContextFinalizer(FREContext ctx);

FREObject sayHello(FREContext ctx, void* functionData, uint32_t argc,
		FREObject argv[]);

FREObject addValues(FREContext ctx, void* functionData, uint32_t argc,
		FREObject argv[]);


FREObject sayHello(FREContext ctx, void* functionData, uint32_t argc,
		FREObject argv[]) {
	const char *out = "Hello from the native code!";
	FREObject result;
	FRENewObjectFromUTF8((uint32_t)(strlen(out) + 1), (uint8_t*) out, &result);
	return result;
}

FREObject addValues(FREContext ctx, void* functionData, uint32_t argc,
		FREObject argv[]) {
		int32_t valueOne = 0;
		int32_t valueTwo = 0;
		FREGetObjectAsInt32( argv[ 0 ], &valueOne );
		FREGetObjectAsInt32( argv[ 1 ], &valueTwo );

		int32_t resultValue = valueOne + valueTwo;

		const char *out = (char)resultValue;

		FREObject result;
		FRENewObjectFromUTF8((uint32_t)(strlen(out) + 1), (uint8_t*) out, &result);
		return result;
}


void ExtensionInitializer(void** extDataToSet,
		FREContextInitializer* ctxInitializerToSet,
		FREContextFinalizer* ctxFinalizerToSet) {
	*extDataToSet = NULL;
	*ctxInitializerToSet = &ContextInitializer;
	*ctxFinalizerToSet = &ContextFinalizer;
}

/**
 * The runtime calls this function when it disposes of the ExtensionContext instance
 * for this extension context.
 */
void ExtensionFinalizer() {
}


void ContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
		uint32_t* numFunctionsToSet, const FRENamedFunction** functionsToSet) {
	char *temp = NULL;
	int i;

	// define an array of functions
	const char *functionNames[] = { "sayHello","addValues", NULL };
	FREFunction functionPtrs[] = { sayHello,addValues, NULL };

	// count number of functions
	*numFunctionsToSet = 0;
	while (functionPtrs[*numFunctionsToSet] != NULL) {
		(*numFunctionsToSet)++;
	}

	FRENamedFunction *functionSet = calloc(*numFunctionsToSet,
			sizeof(FRENamedFunction));

	for (i = 0; i < *numFunctionsToSet; i++) {
		int bufferSize = sizeof(char) * (strlen(functionNames[i]) + 1);
		temp = (char*) malloc(bufferSize);
		strncpy(temp, functionNames[i], bufferSize);
		temp[strlen(functionNames[i])] = '\0';
		functionSet[i].name = (uint8_t*) temp;
		functionSet[i].functionData = NULL;
		functionSet[i].function = functionPtrs[i];
	}

	*functionsToSet = functionSet;
}


void ContextFinalizer(FREContext ctx) {
}

 ANE Library:

package com.math
{
	import flash.external.ExtensionContext;
	
	public class MathLibrary
	{
		private var _ctx:ExtensionContext;
		
		public function MathLibrary()
		{
			this._ctx = ExtensionContext.createExtensionContext( 
				"com.math.MathLibraryNative", null);
		}
		
		public function sayHello(v1:int, v2:int ): Object {
			var result:Object = this._ctx.call( "addValues",v1,v2 );
			return result;
		}
	}
}

 

Where the call is made:

private function onHelloButtonClick(event:MouseEvent):void
		{
			this.extension = new MathLibrary();
			var out:String = new String(this.extension.sayHello(2,4));
			helloLabel.text = out;
		}

 I have the entries <action system="true">run_air_native</action> in the bar-descriptor

and the entry 

<extensions>
<extensionID>com.example.MathLibraryNative</extensionID>
</extensions>

in the app.xml

 

Please let me know where I am going wrong here ?

Also kindly do let me know if there are any good sample apps/tutorials for Passing parameters to native

using ANE in playbook.


Developer
Posts: 185
Registered: ‎04-05-2011
My Device: PlayBook
My Carrier: Bouygues Telecom

Re: Getting Error when running ANE app with parameters

Is it com.math, or com.example? Make sure these ids match..

Julien
Web: smugrik.org Follow: @Smugrik
PlayBook apps:
OSCream
kiPass
Contributor
Posts: 19
Registered: ‎03-11-2012
My Device: Pearl 3G
My Carrier: Vodafone

Re: Getting Error when running ANE app with parameters

Thanks a lot, that really worked. I had to just change the ANE library

code to "com.math.MathLibraryNative", null) and it worked !!!!

 

However still not able to figure out what decides the package name

for the air extension. Any suggestions here ?