[Android Studio] fusetto989:
I am creating a simple application in Android Studio for managing a device connected via wifi using the Volley library.

The app must do this: when you click on the On button the device must turn on and consequently show the image of a light bulb on, while when I click on the Off button the device must turn off and show the image of a light bulb off on the screen . In Postman the interaction with the device works correctly.

When I start the app and click on the on/off button nothing happens, that is, it always shows me an image of an unlit light bulb. The logcat gives me no errors.

By debugging I notice that when the sendAndRequestResponse() method is executed it does not enter the onResponse method but jumps directly to the setRetryPolicy method.

Can you kindly help me? I am a beginner.

MainActivity.java

import androidx.appcompat.app.AppCompatActivity;

import androidx.appcompat.widget.SwitchCompat;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.CompoundButton;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.RelativeLayout;

import android.widget.TextView;

import com.android.volley.Request;

import com.android.volley.RequestQueue;

import com.android.volley.Response;

import com.android.volley.VolleyError;

import com.android.volley.toolbox.StringRequest;

import com.android.volley.toolbox.Volley;

import java.text.BreakIterator;

public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getName();

SwitchCompat switchButton;

LinearLayout imageViewLight;

private RequestQueue mRequestQueue;

TextView buttonState;

private StringRequest mStringRequest;

private String url = "https://192.168.130.13:8081/zeroconf/switch";

@override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

switchButton=findViewById(R.id.switchButton);

imageViewLight=findViewById(R.id.linearL);

TextView buttonState;

buttonState = findViewById(R.id.buttonState);

switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

@override

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

sendAndRequestResponse();

}

});

}

private void sendAndRequestResponse() {

mRequestQueue = Volley.newRequestQueue(this);

mStringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {

@override

public void onResponse(String response) {

TextView myTextView;

if (switchButton.isChecked()) {

imageViewLight.setBackgroundResource(R.drawable.light__02);

buttonState.setText("State : ON");

} else {

imageViewLight.setBackgroundResource(R.drawable.light__01);

buttonState.setText("State : OFF");

}

}

}, new Response.ErrorListener() {

@override

public void onErrorResponse(VolleyError error) {

Log.i(TAG,"Error :" + error.toString());

}

});

mStringRequest.setRetryPolicy(new RetryPolicy() {

@override

public int getCurrentTimeout() {

return 50000;

}

@override

public int getCurrentRetryCount() {

return 50000;

}

@override

public void retry(VolleyError error) throws VolleyError {

}

});

mRequestQueue.add(mStringRequest);

}

}