启动活动时的Android异常:java.lang.IllegalStateException:onCreate()之前的活动不可用的系统服务

时间:2012-01-14 15:51:23

标签: android

当我的Android应用程序启动时,我遇到了这个异常:

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)

这是Class和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,但我没有启动窗口。

提前致谢!     }

1 个答案:

答案 0 :(得分:0)

好的,我发现了问题,抱歉。我复制并粘贴了一些代码,并没有意识到它是使用ProgressDialog.Show()方法声明ProgressDialog对话框,因为它使用系统服务而不允许作为全局var。感谢Jan-Henk的兴趣。