-4
我在我的java代碼中嘗試編譯我的代碼時出現此錯誤。當我嘗試將文本視圖中的文本值變爲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";
............
爲什麼?
編輯:感謝downvote我的問題,是的,我搜索了另一個類似的問題,我已經嘗試過使用靜態方法...然後不崩潰,但var的內容爲空,不起作用在所有。
什麼你廣泛的搜索,彈出? –
使'post'方法非靜態。因爲您無法訪問靜態方法內的非靜態變量。 – iMBMT
「_我無法理解這個錯誤_」你不能?還是沒有試過? – csmckelvey