主要活动上的错误信息:“表达式的非法开始” [英] Error Message on Main Activity: 'illegal start of expression'

查看:130
本文介绍了主要活动上的错误信息:“表达式的非法开始”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个简单的应用程序,如果用户输入文字消息并单击一个按钮,则该消息将显示在下一个视图中。



它曾经可以正常工作,但是后来我添加了几行代码,并将其删除了,现在它不再像以前那样工作了。



编译器不会运行我的代码,并继续说非法的表达方式和;



如果有人可以在这里帮助我,我将不胜感激。
这是我的代码:

 公共类MainActivity扩展了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);


/ **当用户单击发送按钮时调用* /

public void sendMessage(View view){
//在对按钮
的响应Intent intent = new Intent(this,IntroToApp.class);
EditText editText =(EditText)findViewById(R.id.edit_message);
字符串消息= editText.getText()。toString();
intent.putExtra(EXTRA_MESSAGE,消息);
startActivity(intent);
}
}


解决方案

请关闭您的onCreate方法。 myapplication3.MESSAGE;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}



/ **当用户单击发送按钮时调用* /

public void sendMessage(View view){
//响应按钮
做一些事情Intent intent = new Intent(this,IntroToApp.class);
EditText editText =(EditText)findViewById(R.id.edit_message);
字符串消息= editText.getText()。toString();
intent.putExtra(EXTRA_MESSAGE,消息);
startActivity(intent);
}
}


I'm trying to build a simple application where if a user inputs a text message and clicks a button, the message shows on the next view.

It used to work fine, but then I added some lines of code, and deleted it back, and now it does not work again as it used to.

The complier won't run my code, and keep saying 'illegal start of expression' and '; expected'.

I'd appreciate if anyone could help me out here. Here's my code:

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);
    }
}

解决方案

Please close your onCreate method.

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);
    }
   }

这篇关于主要活动上的错误信息:“表达式的非法开始”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆