0
我在這個異常,當我在首發Android應用程序:Android的異常活動時:java.lang.IllegalStateException:的onCreate()之前不爲活動提供系統的服務
01-14 16:40:41.725: E/AndroidRuntime(11341): FATAL EXCEPTION: main
01-14 16:40:41.725: E/AndroidRuntime(11341): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{es.landesoft/es.landesoft.LandeSoftActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
01-14 16:40:41.725: E/AndroidRuntime(11341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
01-14 16:40:41.725: E/AndroidRuntime(11341): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-14 16:40:41.725: E/AndroidRuntime(11341): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-14 16:40:41.725: E/AndroidRuntime(11341): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-14 16:40:41.725: E/AndroidRuntime(11341): at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 16:40:41.725: E/AndroidRuntime(11341): at android.os.Looper.loop(Looper.java:130)
01-14 16:40:41.725: E/AndroidRuntime(11341): at android.app.ActivityThread.main(ActivityThread.java:3691)
01-14 16:40:41.725: E/AndroidRuntime(11341): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 16:40:41.725: E/AndroidRuntime(11341): at java.lang.reflect.Method.invoke(Method.java:507)
01-14 16:40:41.725: E/AndroidRuntime(11341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
這是開始類和Oncreate方法。我知道你不能在onCreate()之前使用 系統服務,我認爲我沒有這樣做,因爲我只用 代碼來激活佈局按鈕。
public class LandeSoftActivity extends Activity {
/** Called when the activity is first created. */
TextView lblEnvio;
EditText txtDestinatarios;
EditText txtAsunto;
EditText txtMensaje;
private String ResStr;
private String ResEnvio;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button botonEnviar = (Button) findViewById(es.landesoft.R.id.btnSend);
botonEnviar.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Thread Hilo = new Thread(new Runnable() {
public void run() {
ResEnvio= EnviarEMailWS();
handler.sendEmptyMessage(0);
}
});
Hilo.start();
lblEnvio.setText(ResEnvio);
}
});
Button BtnSysInfo = (Button) findViewById(es.landesoft.R.id.btnSysInfo);
BtnSysInfo.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Thread Hilo = new Thread(new Runnable() {
public void run() {
ResStr =RequestWSInfo();
handler.sendEmptyMessage(0);
}
});
Hilo.start();
ShowToastMsg(ResStr, 12000);
}
});
lblEnvio = (TextView) findViewById(es.landesoft.R.id.textView1);
txtDestinatarios = (EditText) findViewById(es.landesoft.R.id.editText1);
txtAsunto= (EditText) findViewById(es.landesoft.R.id.txtAsunto);
txtMensaje= (EditText) findViewById(es.landesoft.R.id.txtMensaje);
我希望你能幫助我。我想問題是ProgressDialog,但我沒有啓動窗口。
在此先感謝! }
這是你活動中的所有代碼嗎?如果沒有,請將其餘的郵寄。 – 2012-01-14 15:59:09
好吧,我找到了問題,抱歉。我複製並粘貼了一些代碼,並沒有意識到它聲明瞭使用ProgressDialog.Show()方法的ProgressDialog對話框,該方法不允許作爲全局變量,因爲它使用了系統服務。感謝Jan-Henk對您的關注。 – 2012-01-14 16:05:50
請務必將您的評論發佈爲答案,並將其標記爲正確以幫助他人! – Brandon 2012-01-14 18:05:02