我有我的主類設置和一個工作線程,我在run()
中提出的一個早期請求是調用我的第二個類,名爲login。我這樣做,像這樣:在單獨的類中調用方法
login cLogin = new login();
cLogin.myLogin();
類登錄看起來是這樣的:
package timer.test;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;
public class login extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
}
public void myLogin() {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage(this.getString(R.string.intro));
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Register New Account",
new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
}
});
// add a neutral button to the alert box and assign a click listener
alertbox.setNegativeButton("Login",
new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
}
});
// show it
alertbox.show();
}
10-01 14:33:33.028: ERROR/AndroidRuntime(440):
java.lang.RuntimeException: Unable to start activity ComponentInfo{timer.test/timer.test.menu}:
java.lang.IllegalStateException:
System services not available to Activities before onCreate()
我把onCreate
的,但仍然有同樣的問題。我怎樣才能解決這個問題?
爲什麼不讓登錄活動成爲主要活動? – Ronnie