アラートダイアログの操作中にエラーが発生します。4.1ジェリービーンズSDKを使用しています。ユーザーのインターネット接続を確認したいのですが、GPSが利用可能かどうかを確認します。
エラーライン:
myAlertDialog = alertDialog.create();
私の制御機能:
public void kontrol(){
LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
if(isConn()){
{
startActivity(new Intent (MainActivity.this,GPSanasayfa.class));
}
}
else{
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog.setMessage("Uygulamayı kullanabilmek için internet bağlantınızın aktif olması gerekmektedir");
alertDialog.setPositiveButton("Tamam", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
});
myAlertDialog = alertDialog.create(); //I get error this line
myAlertDialog.show();
}
}
else{
startActivity(new Intent (MainActivity.this,NormalAnasayfa.class));
}
}
エラーログ:
09-12 09:06:28.685: E/AndroidRuntime(825): FATAL EXCEPTION: Thread-93
09-12 09:06:28.685: E/AndroidRuntime(825): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
09-12 09:06:28.685: E/AndroidRuntime(825): at android.os.Handler.<init>(Handler.java:121)
09-12 09:06:28.685: E/AndroidRuntime(825): at android.app.Dialog.<init>(Dialog.java:107)
09-12 09:06:28.685: E/AndroidRuntime(825): at android.app.AlertDialog.<init>(AlertDialog.java:114)
09-12 09:06:28.685: E/AndroidRuntime(825): at android.app.AlertDialog$Builder.create(AlertDialog.java:913)
09-12 09:06:28.685: E/AndroidRuntime(825): at com.minor.cepcadisiv3.MainActivity.kontrol(MainActivity.java:55)
09-12 09:06:28.685: E/AndroidRuntime(825): at com.minor.cepcadisiv3.MainActivity$2.run(MainActivity.java:78)
09-12 09:06:28.685: E/AndroidRuntime(825): at java.lang.Thread.run(Thread.java:856)
onCreateでこの関数を呼び出します。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pdialog = ProgressDialog.show(MainActivity.this, "Kontrol Ediliyor...", "İnternet ve GPS erişiminiz kontrol ediliyor.",true);
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(2000);
kontrol();
pdialog.dismiss();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
}).start();
}