主要活动的错误消息:'非法开始表达'

时间:2014-12-22 11:49:08

标签: android compiler-errors

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

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

编译器不会运行我的代码,并继续说'非法开始表达'和';预期”。

如果有人能帮助我,我会很感激。 这是我的代码:

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

3 个答案:

答案 0 :(得分:0)

请关闭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);
    }
   }

答案 1 :(得分:0)

试试这个。希望它能奏效。

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

答案 2 :(得分:0)

应该是这样的。

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