0
我剛開始學習android編程,並開始在developer.android.com上的在線教程。一直在一步步地檢查代碼,但現在出現錯誤,無法繼續。以下開發者錯誤「方法findViewByID(int)未定義」下面是developer.android.com教程
就行了:
EditText editText = (EditText) findViewByID(R.id.edit_message);
我得到錯誤「的方法findViewByID(INT)是未定義的類型MainActivity」
代碼似乎是相同的東西顯示在該網站,所以不知道我在做什麼錯。任何幫助讚賞。下面全部代碼:
package com.example.myfirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/** Called when the user clicks the send button */
public void sendMessage(View view) {
// do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewByID(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}