我有一個與Web服務連接的應用程序。 當我開始我的應用程序調用類:需要解決我的錯誤與背景的Android
public class CaApplication extends Application {
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
DataRetrieve dr ;
ProgressDialog progressBar;
progressBar = new ProgressDialog(this);
//progress bar orientation
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// Text that will appear on the progress bar dialog
progressBar.setMessage("Loading...");
//set whether the progress bar is cancelable or not
progressBar.setCancelable(false);
progressBar.show();
dr = new DataRetrieve();
}
}
我得到錯誤:
11-25 15:39:36.698: E/AndroidRuntime(30429): Caused by: 11-25 15:39:36.698: E/AndroidRuntime(30429): java.lang.RuntimeException: Unable to create application com.example.storeclientdropdown.CambiumApplication: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3974)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.app.ActivityThread.access$1300(ActivityThread.java:127)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.os.Looper.loop(Looper.java:137)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.app.ActivityThread.main(ActivityThread.java:4441)
11-25 15:39:36.698: E/AndroidRuntime(30429): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 15:39:36.698: E/AndroidRuntime(30429): at java.lang.reflect.Method.invoke(Method.java:511)
11-25 15:39:36.698: E/AndroidRuntime(30429): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-25 15:39:36.698: E/AndroidRuntime(30429): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-25 15:39:36.698: E/AndroidRuntime(30429): at dalvik.system.NativeStart.main(Native Method)
11-25 15:39:36.698: E/AndroidRuntime(30429): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.view.ViewRootImpl.setView(ViewRootImpl.java:517)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.app.Dialog.show(Dialog.java:278)
11-25 15:39:36.698: E/AndroidRuntime(30429): at com.example.storeclientdropdown.CambiumApplication.onCreate(CambiumApplication.java:35)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
11-25 15:39:36.698: E/AndroidRuntime(30429): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3971)
11-25 15:39:36.698: E/AndroidRuntime(30429): ... 10 more
在DataRetrive我從web服務的所有數據之後,我打電話MainActivity。 什麼是錯的,我怎樣才能修復這個錯誤。我嘗試:progressBar = new ProgressDialog(this);
,progressBar = new ProgressDialog(getApplicationContext());
,progressBar = new ProgressDialog(getBaseContext);
但沒有結果。
你不可錯過的''Application'到Context'一個'Dialog',一個'Dialog'被綁定到'Activity'。 – Luksprog