1

在以下代码行中...

ProgressDialog progressDialog = ProgressDialog.show(getBaseContext(), "LOADING_TITLE", "LOADING_MESSAGE");

代替 getBaseContext() 我试过了......

getApplicationContext() // returns "java.lang.NullPointerException"
getBaseContext() // returns "java.lang.NullPointerException"
(NativeActivity)getApplicationContext()
this // returns "The method show(Context, CharSequence, CharSequence) in the Type ProgressDialog is not applicable for the arguments(new Runnable(){}, String, String)"
NativeActivity.this // returns "java.lang.NullPointerException"
NativeActivity.this.getApplicationContext() // returns "java.lang.NullPointerException"
NativeExtension.context.getActivity().getBaseContext() // returns “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”
myActivity.getApplicationContext() // returns “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”
myActivity.getBaseContext() // returns “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”

其中。我不确定为什么它不起作用。在扩展 FREContext 的 NativeExtensionContext 中,我使用 getActivity() 将活动传递给 NativeActivity。一切正常,但是当我尝试获取对上下文的引用时,我得到一个“Nullpointerexception”或“android.view.WindowManager$BadTokenException: Unable to add window - token null is not for an application”。

任何有使用 Adob​​e AIR Native Extensions 和/或 Android Java 经验的人都会很棒。

4

2 回答 2

0
NativeExtension.context.getActivity().getBaseContext() // this should work.

我能想到的唯一一件事就是确保您在 Activity 内部工作。也就是说,您从 FREFunction 实例初始化的 Activity。

于 2012-11-02T16:50:46.533 回答
0

将此添加到您的课程中:

public static FREContext myANEContext=null;

....
....

  ProgressDialog progressDialog = ProgressDialog.show(myANEContext.getActivity().getBaseContext(), "LOADING_TITLE", "LOADING_MESSAGE");

FREFunction不要忘记在使用你的类之前传递值:

  public class MyANEfunction implements FREFunction{


    @Override
      public FREObject call(final FREContext context, FREObject[] args) {
      try{
            myANEClass.myANEContext=context;

         ....
于 2014-01-18T21:53:22.987 回答