gpt4 book ai didi

java - 表达式的非法开始(Android)

转载 作者:行者123 更新时间:2023-12-01 21:55:16 26 4
gpt4 key购买 nike

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

它是关于获取用户输入然后将 toast 作为输出

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

编译此代码时出现错误非法开始表达式

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com