以下开发者错误“方法findViewByID(int)未定义”下面是developer.android.com教程
问题描述:
我刚开始学习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);
}
}
答
应该findViewById(..)
,不findViewByID(...)
。 Java区分大小写。