Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:13:08+00:00 2026-06-11T05:13:08+00:00

I get some error working with alert dialog. I use 4.1 jelly bean sdk.

  • 0

I get some error working with alert dialog. I use 4.1 jelly bean sdk. I want to check user’s internet connection and gps is available or not.

Error Line:

myAlertDialog = alertDialog.create();

My control function:

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)); 
            }

        }

Error Log:

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)

I call this function in 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();  

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:13:09+00:00Added an answer on June 11, 2026 at 5:13 am

    I solved problem about like this.

    public Activity activity = MainActivity.this;
    

    and here is the code of function

    activity.runOnUiThread(new Runnable() {
                        public void run() {
                           AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                    builder.setMessage("Uygulamayı kullanabilmek için internet bağlantınızın aktif olması gerekmektedir")
                           .setCancelable(false)
                           .setPositiveButton("Tamam", new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int id) {
                                    System.exit(0);
                               }
                           });
                    AlertDialog alert = builder.create();
                    alert.show(); 
                        }
                    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to compile the Rigi source code but I get some error while
When I want to update the eclipse I get the following error: Some sites
I get an EOFError end of file error. when running PrivatePub.publish_to(/dir/file, Some Text) within
I am trying to parse some XML, however, I get the error above this
I'm messing around with some windows functions using p/invoke. Occasionally, I get an error
I'm developing against a DB2 database, and at some point I get an error
For some reason javascript functions are not working right now. function alert(){ alert('Close') }
I'm trying to get some basic ajax working on rails. I have a comon
I am currently working on a project about taxis. I want to display some
For some reason I can't get this to work. All I want to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.