我正在尝试按照 Google 的本教程使用 Android Studio 创建您自己的 Android 应用。但是当我按照此页面上的第 4 步操作时:http://developer.android.com/training/basics/firstapp/starting-activity.html Android Studio 最终出现此错误:
Cannot resolve symbol 'View'
这就是我的代码现在的样子:
public class MainActivity extends ActionBarActivity {
/** Called when the user clicks the Send button */
public void sendMessage(View view) { <--- (This line ends up with the error)
// Do something in response to button
}
@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.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这段代码有什么问题?我对java没有经验,在查看了其他问题后,我仍然找不到正确的解决方案。
感谢您的帮助!
最佳答案
我认为您忘记包含 View 的导入语句。在您的代码中添加以下导入
import android.view.View;
关于java - Android Studio 错误 : Cannot resolve symbol 'View' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27779724/