3

私は現在、ネイティブアラートポップアップ用のAndroidANEの作成に取り組んでいます。私は今、JavaとAS3の両方のコードがうまくいくと思うところまで来ていますが、それを使おうとするとエラーが発生します。

メインスレッド(中断:TypeError:エラー#1009:nullオブジェクト参照のプロパティまたはメソッドにアクセスできません。)

私の問題は、このエラーがどこから来ているのか本当にわからないことです。私の考えでは、ANEファイルが正しく作成されていないか、extension.xmlファイルに何か問題がありますが、よくわかりません。

このプロジェクトがどのように設定されているかについて、できるだけ多くの情報を提供するように努めます。現在、私はこのANEを小さなテストアプリケーションで使用しようとしています。

まず、フォルダの設定:

ANEextensions-

     Alert_Java(私のJavaプロジェクトを保持しています)

          (Android / Javaで作成されたアセット。これらが重要かどうかはわかりません。重要な場合はリストします)

          src

               com

                    fa

                         ne                        

                              アンドロイド

                                   AlertContext.java

                                   AlertExtension.java

                                   ShowAlert.java

     Alert_AS

          置き場

               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>

そのボタンをクリックすると、エラーが発生します。

テストアプリとAS3Alert_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を削除し、getcontext関数をAlertContext.javaに移動しました。これで問題が解決すると思っていましたが、それでも同じ結果が得られます。これが私のコードです:

AlertContext.java、私はcreateContextメソッドがvar a:Alert = new Alert();の後に起動されると想定しています。

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;
}

}
4

4 に答える 4

1

クイックヒント、拡張機能が利用可能かどうかを通知する関数を作成します。

public static function isSupported():Boolean
{
     return extContext != null;
}

お役に立てれば。

また、ネイティブ拡張機能のデフォルトの実装を追加することをお勧めします。これは、アクションスクリプトで完全に記述でき、エミュレーターでアプリを実行するときに使用されます。

詳細については、こちらをご覧ください。

http://www.adobe.com/devnet/air/articles/extending-air.html

于 2011-12-11T22:32:10.003 に答える
0

拡張機能をFlashBuilderのAndroidプラットフォームにリンクしましたか?「FlexBuildPath」の「NativeExtension」タブに追加するだけでは不十分です。また、のチェックボックスをオンにする必要があります。

「FlexBuildPackaging」>>「GoogleAndorid」>>>「NativeExtension」

また、あなたは違いを見てみることができます、そして、maby何かが私の目的から助けになります: NativeAlert

于 2012-03-05T15:10:50.200 に答える
0

私はあなたの質問に本当に答えることができません。私はJavaを知りません(私にとっては疑似ActionScriptのように読めます)。ただし、これはあなたにいくつかの助けを提供するかもしれません、そしてあなたが問題を簡単に見つけるかもしれないここに戻って参照することができる誰か。

Piotr Walczyszynは、Androidネイティブアラート/プッシュ拡張機能をここで作成しました:http: //www.riaspace.com/2011/09/as3c2dm-air-native-extension-to-push-notifications-with-c2dm/

コメントの中で、iOSのネイティブアラートに関する広範なチュートリアルを持っている別の人もここで見つけました:http ://www.liquid-photo.com/2011/10/28/native-extension-for-adobe-air-and-ios -101 /

私はピョートルの投稿へのコメントを読んでいました、そして彼が言ったいくつかのことは私にこの行かどうか疑問に思います

extContext = ExtensionContext.createExtensionContext("com.fa.alerts", null);

問題を引き起こしている/関連している可能性があります

これがあなたや他の人に役立つことを願っています。

皆さん、頑張ってください!

トッド

...プッシュ通知オプション/実行可能性=Dの調査に戻る

于 2012-05-05T23:46:30.483 に答える
0

私もあなたの問題にぶつかり続けました。

私が(いくつかの変更を加えて)仕事に取り掛かることができた唯一のチュートリアルは、ここにあるものです。

http://www.adobe.com/devnet/air/articles/developing-native-extensions-air.html

-swf-version 13フレックスライブラリコンパイラに追加する必要がありました。

そして-tsa none、ANEファイルをビルドするためにadtコマンドに追加する必要がありました。

于 2012-05-23T19:58:28.617 に答える