我正在尝试构建一个简单的应用程序,如果用户输入文本消息并单击一个按钮,则该消息将显示在下一个 View 中。
它曾经可以正常工作,但是后来我添加了几行代码,并将其删除了,现在它不再像以前那样工作了。
编译器不会运行我的代码,并继续说“非法的表达开始”和“;预期'。
如果有人可以在这里帮助我,我将不胜感激。
这是我的代码:
public class MainActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = "com.yhmac.myapplication3.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, IntroToApp.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
最佳答案
请关闭您的onCreate方法。
public class MainActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = "com.yhmac.myapplication3.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, IntroToApp.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
关于android - 关于主要 Activity : 'illegal start of expression' 的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27602133/