1

I have a TextView which contains 'F' or 'M', based on user selection. So in my activity I should have to assign a url path relatively to the letter in this TextView. I have created two static strings like so:

private static final String urlman = "http://www.example.com/man.php";
private static final String urlwoman = "http://www.example.com/woman.php";

Then I've created this control point:

private void controlsexuser() {
    String sexuser = sexController.getText().toString();
    sexController.setText(sexuser);
    if (sexuser.trim().equals("F")) {
        String sceltaServizio = urlwoman;
    }else {
        String sceltaServizio = urlman;
    }
}

Then in AsyncTask, I've tried to put the new string:

DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
            HttpPost httppost = new HttpPost(sceltaServizio);

Unfortunately, the app stops and I don't know why. Any suggestions would be apreciated! Thanks

7
  • sceltaServizio is null Commented Sep 23, 2015 at 17:50
  • I could imagine...but i have put after string sceltaservizio = urlman a log and i can see that it isn't null...string is correct... Commented Sep 23, 2015 at 17:53
  • if controlsexuser() is the code you are running, the some you posted, there is not way that sceltaServizio is not null in your AsyncTask Commented Sep 23, 2015 at 17:55
  • I have declared a string null sceltaservizio, and if i log it after run controlsexuser, it contains the url setted in urlman or url woman... Were is the error? Commented Sep 23, 2015 at 18:09
  • and if i log it after run controlsexuser, it contains the url setted in urlman or url woman, where are you logging it ? Commented Sep 23, 2015 at 18:13

1 Answer 1

1

Check the visibility(Access Modifier) of sceltaServizio.

Sign up to request clarification or add additional context in comments.

3 Comments

sorry, i shouldn't know how do it
use log inside AsyncTask once and before DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams()); line and check what value its returning.
Good suggestion! variable in AsyncTask has lost his value and is null. So, i have changed code, inserted a new textview and putted inside it value. It works properly now. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.