作者:赵小锅2502889451 | 来源:互联网 | 2023-05-28 13:04
我正试图从谷歌跟随这个教程用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经验,在查看其他问题后,我仍然无法找到合适的解决方案.
谢谢你的帮助!
1> BeingMIAkash..:
我想你忘了为View包含import语句.在代码中添加以下导入
import android.view.View;