我目前正在为本机警报弹出窗口创建一个Android ANE。 我现在处于这样的地步,我认为我的Java和AS3代码都很好,但是当我尝试使用它时我遇到了错误。
主线程(已挂起:TypeError:错误#1009:无法访问空对象引用的属性或方法。)
我的问题是我真的不确定这个错误来自哪里。 我的想法是我没有正确构建ANE文件或者我的extension.xml文件中有问题,但我真的不太确定。
我将尝试尽可能多地提供有关此项目如何设置的信息。 现在我正试图在一个小的测试应用程序中使用这个ANE。
首先,文件夹设置:
ANEextensions- Alert_Java (holding my Java project) (Android/Java created assets. Not sure if these are important or now. If so I will list them) src com fa ne android AlertContext.java AlertExtension.java ShowAlert.java Alert_AS bin AlertAndroidAS.swc src Alert.as extension.xml
因为我认为这是正确的,所以我不打算发布我的java代码。 但是,如果有人愿意花一些时间帮助我解决这个问题想看看,请告诉我。
这是我的extensions.xml文件
<extension xmlns="http://ns.adobe.com/air/extension/2.5">
<id>com.fa.alerts</id>
<versionNumber>1.0</versionNumber>
<platforms>
<platform name="Android-ARM">
<applicationDeployment>
<nativeLibrary>AndroidAlert.jar</nativeLibrary>
<initializer>com.fa.ne.android.AlertExtension</initializer>
<finalizer>com.fa.ne.android.AlertExtension</finalizer>
</applicationDeployment>
</platform>
</platforms>
</extension>
这是我的Alert.as文件:
package {
import flash.events.EventDispatcher;
import flash.external.ExtensionContext;
public class Alert extends EventDispatcher{
public static var extContext:ExtensionContext = null
public function Alert(){
super();
extContext = ExtensionContext.createExtensionContext("com.fa.alerts", null);
}
public static function androidAlert(aTitle:String, aMsg:String, aNeg:String = "Cancel", aPos:String = "Ok"):void{
extContext.call("showAlert", aTitle, aMsg, aNeg, aPos);
}
}
}
这是我用来测试的存根应用程序
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
<fx:Script>
<![CDATA[
protected function spawnAne(event:MouseEvent):void{
var a:Alert = new Alert();
Alert.androidAlert("test","testing");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button click="spawnAne(event)" />
</s:View>
现在单击该按钮是导致错误的原因。
我的测试应用程序和AS3 Alert_AS项目之间没有任何类型的swc或链接。 我正在使用Flash Builder 4.6使用IDE工具导入ANE文件。
为了构建我的ANE,我在这篇文章中使用了一个经过轻微修改的bash脚本: http ://gotoandlearn.com/play.php?id = 149 by Lee Brimelow
# path to YOUR Android SDK
export AIR_ANDROID_SDK_HOME="my sdk"
# path to the ADT tool in Flash Builder sdks
ADT="my adt"
# native project folder
NATIVE_FOLDER=Alert_Java
# AS lib folder
LIB_FOLDER=Alert_AS
# name of ANE file
ANE_NAME=AndroidAlert.ane
# JAR filename
JAR_NAME=AndroidAlert.jar
# cert path
CERT_NAME=cert.p12
# cert password
CERT_PASS=password
#===================================================================
echo "****** preparing ANE package sources *******"
rm ${ANE_NAME}
rm -rf ./build/ane
mkdir -p ./build/ane
mkdir -p ./build/ane/Android-ARM
mkdir -p ./build/ane/Android-ARM/res
# copy resources
cp -R ./${NATIVE_FOLDER}/res/* ./build/ane/Android-ARM/res
# create the JAR file
jar cf ./build/ane/Android-ARM/${JAR_NAME} -C ./${NATIVE_FOLDER}/bin .
# grab the extension descriptor and SWC library
cp ./${LIB_FOLDER}/src/extension.xml ./build/ane/
cp ./${LIB_FOLDER}/bin/*.swc ./build/ane/
unzip ./build/ane/*.swc -d ./build/ane
mv ./build/ane/library.swf ./build/ane/Android-ARM
echo "****** creating ANE package *******"
"$ADT" -package -storetype PKCS12 -keystore ./cert.p12 -storepass password -tsa none \
-target ane \
${ANE_NAME} \
./build/ane/extension.xml \
-swc ./build/ane/*.swc \
-platform Android-ARM \
-C ./build/ane/Android-ARM/ .
echo "****** ANE package created *******"
我知道这有点长,但任何帮助将不胜感激! 如果您需要更详细的说明,请随时告诉我
添加了Java代码
我稍微修改了原始代码。 我删除了AlertExtension.java并将get上下文函数移动到AlertContext.java。 我以为这会解决我的问题,但我仍然得到相同的结果。 这是我的代码:
AlertContext.java,我假设在var a:Alert = new Alert()之后触发了createContext方法;
package com.fa.ne.android;
import java.util.Map;
import java.util.HashMap;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREExtension;
import com.adobe.fre.FREFunction;
public class AlertContext extends FREContext implements FREExtension {
@Override
public FREContext createContext(String type){
return new AlertContext();
}
@Override
public void initialize(){
}
@Override
public void dispose() {
}
@Override
public Map<String, FREFunction> getFunctions() {
HashMap<String, FREFunction> functionMap = new HashMap<String, FREFunction>();
functionMap.put("showAlert", new ShowAlert());
return functionMap;
}
}
这是我的ShowAlert课程
package com.fa.ne.android;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;
public class ShowAlert implements FREFunction {
@Override
public FREObject call(FREContext aContext, FREObject[] aPassedArgs) {
//get activity
Activity a = aContext.getActivity();
//grabbing context
final FREContext context = aContext;
try{
//getting the title and msg for alert as string
String title = aPassedArgs[0].getAsString();
String message = aPassedArgs[1].getAsString();
String negitive = aPassedArgs[3].getAsString();
String positive = aPassedArgs[4].getAsString();
//creating the alert builder with the activity
Builder builder = new Builder(a);
//setting the title and msg
builder.setTitle(title);
builder.setMessage(message);
//setting up buttons, negative and positive, each with an event so we can listen in AS3
//doing listeners inline
builder.setNegativeButton(negitive, new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int dig){
context.dispatchStatusEventAsync("nativeAlert", "negitive");
}
}).setNeutralButton(positive, new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int dig){
context.dispatchStatusEventAsync("positiveAlert", "positive");
}
});
//done building, time to alert and return
builder.create().show();
return FREObject.newObject(true);
//error handeling
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (FRETypeMismatchException e) {
e.printStackTrace();
} catch (FREInvalidObjectException e) {
e.printStackTrace();
} catch (FREWrongThreadException e) {
e.printStackTrace();
}
return null;
}
}