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 8508587
In Process

The Archive Base Latest Questions

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

This is my main thread: Thread t = new Thread(){ @Override public void run()

  • 0

This is my main thread:

Thread t = new Thread(){

    @Override
    public void run() {
        // TODO Auto-generated method stub
        for(int i = 0; i < passes.length; i++){
            progPass.setProgress(i);
            WifiConfiguration wc = new WifiConfiguration();
            wc.SSID = "\"" + dbw.getSsid() + "\"";
            wc.preSharedKey  = "\"" + passes[i] + "\"";
            wc.status = WifiConfiguration.Status.ENABLED;   
            wc = configureCapabs(wc, dbw.getCapability());
            int res = wifi.addNetwork(wc);
            //Toast.makeText(this, "add Network returned " + res , Toast.LENGTH_SHORT).show();
            boolean b = wifi.enableNetwork(res, true);        
            //Toast.makeText(this, "enableNetwork returned " + b , Toast.LENGTH_SHORT).show();
            if(!b) continue;
            try {
                synchronized(this){
                    this.wait();
                }
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            boolean fin = wifi.getConnectionInfo() != null;
            if(fin) break;
        }
        progPass.dismiss();
        this.interrupt();
    }

};

It checks if wifi uses one of more common passwords. When the on the wait line it waits for notification from broadcast receiver, here is its code:

public class ConnectivityActionReceiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
        NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if(networkInfo.isConnected()) {
            // Wifi is connected
            Toast.makeText(context, "Wifi is connected: " + String.valueOf(networkInfo), Toast.LENGTH_SHORT).show();
            synchronized(this){
                notifyAll();
            }
        }
    } else if(intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
        NetworkInfo networkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI && ! networkInfo.isConnected()) {
            // Wifi is disconnected
            Toast.makeText(context, "Wifi is disconnected: " + String.valueOf(networkInfo), Toast.LENGTH_SHORT).show();
        }
    } else if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)){
        int esr = intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, 0);
        if(esr != 0){
            Toast.makeText(context, Integer.toString(esr), Toast.LENGTH_LONG).show();
            synchronized(this){
                notifyAll();
            }
        }

    }
}

Here it is registered Manifest:

 <receiver
        android:name="ConnectivityActionReceiver"
        android:enabled="true"
        android:label="ConnectivityActionReceiver" >
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            <action android:name="android.net.wifi.STATE_CHANGE" />
            <action android:name="android.net.wifi.supplicant.STATE_CHANGE" />
        </intent-filter>
    </receiver>

It has an instance in the same class as the thread:

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    IntentFilter filter = new IntentFilter();
    this.registerReceiver(car, filter);
}

The toast that should appear in onReceive method shows up, meaning that messages are received, but the notification doesn’t reach the thread, which means it’s stuck in waiting.

  • 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-11T03:12:09+00:00Added an answer on June 11, 2026 at 3:12 am

    You’re using two different objects for synchronization! One is the thread object, one is the ConnectivityActionReceiver. When you’re using this:

     synchronized(this){
          this.wait();
     }
    

    you’re locking on the current instance, hence you are locking on different instances in your case.

    The solution is to call wait/notify on a common, globally visible object:

    final Object signal = new Object();
    
    // in the waiting thread
    synchronized(signal) {
        signal.wait();
    }
    
    // in the signaling thread
    synchronized(signal) {
        signal.notifyAll();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: setContentView(R.layout.splashscreen); Thread timer = new Thread() { @Override public void run() { //
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView = (TextView) findViewById(R.id.text); new Thread(new
I have written this piece of code public class Test{ public static void main(String[]
I am in this scenario: at a certain point, the main thread need to
Exception in thread main java.lang.NullPointerException at Library.loadBooks(Library.java:179) at UseLibrary.main(UseLibrary.java:105) This error makes me crazy!
I'm having a problem where I receive this error: Exception in thread main java.lang.NullPointerException
My program is like this ( main.c ): #include <stdlib.h> #include <stdio.h> void main(){
Here is the code: public static void main(String[] args) { SocketWorker worker = null;
I am trying to have my main thread spawn off a new thread and,
In the below shown html i have this main div as cxfeeditem feeditem and

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.