学习编码..有人可以帮帮我吗

关于,获取用户输入,然后将吐司作为输出

public class MainActivity extends ActionBarActivity {

private EditText input;
private Button output;


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

    addListenerOnButton();
}

public void addListenerOnButton() {
    input = (EditText) findViewById(R.id.editText input);
    output = (Button) findViewById(R.id.button output);
    output.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast toast;
            toast = new Toast(getApplicationContext());
            toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
            toast.makeText(MainActivity.this, input.getText(), toast.LENGTH_SHORT).show();
        }
    });
}


在编译此..am时出现错误的非法开始表达式

C:\Users\VG\AndroidStudioProjects\MakeToast\app\src\main\java\com\example\vg\maketoast\MainActivity.java
Error:(29, 54) error: ')' expected
Error:(29, 60) error: illegal start of expression
Error:(30, 51) error: ')' expected
Error:(30, 58) error: illegal start of expression
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.

最佳答案

input = (EditText) findViewById(R.id.editText input);
output = (Button) findViewById(R.id.button output);


input = (EditText) findViewById(R.id.editText /*input*/);
output = (Button) findViewById(R.id.button /*output*/);

关于java - 非法开始表达(Android),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34490392/

10-11 20:26