我刚开始学习android编程,并在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);
}
}
答案 0 :(得分:0)
应该是findViewById(..)
,而不是findViewByID(...)
。 Java区分大小写。