-4
내 코드를 컴파일하려고하면이 코드가 오류가 발생합니다. 이것은 내 textview에서 텍스트의 값을 var로 가져 오려고 할 때 발생합니다. 나는 다른 방법에서 잘 작동하기 때문에이 오류를 이해할 수 없다.비 정적 메서드에 대한 정적 참조를 만들 수 없습니다.
왜 이런 일이 발생하며 어떻게 해결할 수 있습니까?
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";
............
왜?
EDIT : 내 질문에 답해 주셔서 감사합니다. 비슷한 질문이 있습니다. 정적 메서드를 사용하여 이미 시도했지만 ... 충돌하지는 않지만 var의 내용은 null이며 작동하지 않습니다. 조금도.
당신의 광범위한 검색은 무엇을 가져 왔나요? –
'post' 메소드를 정적이 아니게 만듭니다. 정적 메서드 내에서 비 정적 변수에 액세스 할 수 없으므로 – iMBMT
"_이 오류를 이해할 수 없습니다 _"할 수 없습니까? 아니면 시도하지 않았습니까? – csmckelvey