I have this in my java code, when I try to compile my code I get an error. This happens when I try to get the value of the text in my textview into a var. I cannot understand this error because It works fine in the other method.
Why happens this and how can I fix it?
public class MainActivity extends Activity {
public EditText editText;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(MainActivity.this, "onCreate", Toast.LENGTH_LONG).show();
//setupMessageButton();
editText = (EditText) findViewById(R.id.editText1);
textView = (TextView)findViewById(R.id.tvIsConnected);
}
public void btnDisplayMessage(View view){
//HERE WORKS FINE
String missatge = editText.getText().toString();
}
public static String POST(String url){
InputStream inputStream = null;
String result = "";
//HERE CRASHES
String missatge = "red"//editText.getText().toString(); GIVES ERROR
String usuario = "foo";
............
WHY?
EDIT: Thanks for downvote my question, Yes, I searched for another similar questions and I've already tried with static method...then don't crash but the content of the var is null and don't work at all.