- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我似乎无法理解为什么会这样。这段代码:
mProgressDialog = ProgressDialog.show(this, "", getString(R.string.loading), true);
工作得很好。但是,这段代码:
mProgressDialog = ProgressDialog.show(getApplicationContext(), "", getString(R.string.loading), true);
抛出以下异常:
W/WindowManager( 569): Attempted to add window with non-application token WindowToken{438bee58 token=null}. Aborting.
D/AndroidRuntime( 2049): Shutting down VM
W/dalvikvm( 2049): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
E/AndroidRuntime( 2049): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 2049): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tastekid.TasteKid/com.tastekid.TasteKid.YouTube}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
E/AndroidRuntime( 2049): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
E/AndroidRuntime( 2049): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 2049): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
E/AndroidRuntime( 2049): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
E/AndroidRuntime( 2049): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2049): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2049): at android.app.ActivityThread.main(ActivityThread.java:4203)
E/AndroidRuntime( 2049): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2049): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2049): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 2049): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
E/AndroidRuntime( 2049): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2049): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
E/AndroidRuntime( 2049): at android.view.ViewRoot.setView(ViewRoot.java:460)
E/AndroidRuntime( 2049): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
E/AndroidRuntime( 2049): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/AndroidRuntime( 2049): at android.app.Dialog.show(Dialog.java:238)
E/AndroidRuntime( 2049): at android.app.ProgressDialog.show(ProgressDialog.java:107)
E/AndroidRuntime( 2049): at android.app.ProgressDialog.show(ProgressDialog.java:90)
E/AndroidRuntime( 2049): at com.tastekid.TasteKid.YouTube.onCreate(YouTube.java:45)
E/AndroidRuntime( 2049): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
E/AndroidRuntime( 2049): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
E/AndroidRuntime( 2049): ... 11 more
任何想法为什么会发生这种情况?我从 onCreate
方法调用它。
最佳答案
我正在使用 API 级别 7 的 Android 版本 2.1。我遇到了这个(或类似的)问题并通过使用这个解决了:
Dialog dialog = new Dialog(this);
而不是这个:
Dialog dialog = new Dialog(getApplicationContext());
希望这会有所帮助:)
关于Android:ProgressDialog.show() 使用 getApplicationContext 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1561803/
我确定我昨晚没有做任何奇怪或错误的事情。昨晚,我仍然能够 Toast.makeText(getApplicationContext(), "Some String", Toast.LENGTH_SHO
首先是Toast.makeText()的格式: public static Toast makeText (Context context, CharSequence text, int durati
我正在尝试获取用户的位置,这似乎给我带来了麻烦。当我调用 distanceBetween() 来查看测试是否正常工作时,我在 getApplicationContext() 处收到 NullPoint
我正在关注本教程: http://www.tutos-android.com/importer-ajouter-certificat-ssl-auto-signe-bouncy-castle-andr
我是一名 Android 初学者,制作了一个简单的 Service 示例。 但在单个代码中 getApplicationContext() 方法的行为有所不同,请检查 MainActivity 的注释
我尝试了以下代码来扩展 Activity ,它运行得很好,但现在我更改了代码以使用扩展 fragment 。我在互联网上搜索并找到了 getActivity() 函数来调用 query() 和其他函数
我正在尝试通过应用程序上下文保存位置,因此我执行了以下操作: 我的应用类: 导入android.app.Application; 导入 com.google.android.maps.GeoPoint
我想使用异步事件对输入到 texbox 中的文本进行 toast ,例如。按下按钮。它编译没有错误,但按下按钮时没有任何反应。从我在论坛上收集到的信息来看,我的背景是错误的。有人能帮我吗?下面是代码:
我已经根据现有 Android 项目中的另一个类指定了一个类。 addRow() 方法应该动态地将行添加到表中。创建新的 TextView 以添加到我的行时以及创建该行时,我应该指定“上下文”。当前的
我正在 Android Froyo 系统上开发一个应用程序,一切都很好,除了当我创建一个服务时,该服务会产生几个线程。在其中一个线程中,我想停止服务。显然 stopService() 超出了线程类的范
我正在尝试以下代码,其中服务正在实现我的监听器: public class MyListenerClass extends Service implements MyListenerInterface
我有一个 fragment ,允许用户输入消息和消息将被传递到的电话号码。我收到错误消息“无法解析方法 getApplicationContext()” 我在这里查看了答案 the method ge
我总是得到这个 java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context an
我正在尝试使用一种方法从布局生成位图并将位图保存到内存中的文件中。但是,getApplicationContext() 未解析。 方法代码如下 private void generateAnd
我有扩展 Application 类的 VideoApplication 类。我已经在此类中创建了我的其他 Java 类的对象,以便我可以通过 Activity 传递它。 public class V
我有一个存储应用上下文信息的应用程序。应用上下文信息在扩展 Application 类的 MyApp 类中的 Activity 之间共享。 我正在为我的 Activity 编写单元测试,并且我想检查当
有谁知道如何在 monodroid 中获取应用程序上下文(我正在寻找 getApplicationContext() 的 monodroid 实现)?我试过 Application.Applicati
如果用户没有输入用户名和密码,我试图弹出消息,但是我的问题是 getApplicationcontext(),它说“无法解析方法”。我如何解决它? - - - - - - - - - - - - -
我在使用外部数据库时遇到问题。DB位于 Assets 字典中。 我正在使用https://github.com/jgilfelt/android-sqlite-asset-helper打开数据库。 下
我正在创建一个应用程序单例,用于在 Activity 之间共享数据。 AppData(单例) import android.app.Application; public class AppData
我是一名优秀的程序员,十分优秀!