Issue
Learning to code.. Can someone help me out
Its about, getting the user input and then toast as an output
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();
}
});
}
While compile this ..am getting an error illegal start of expression
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.
Solution
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*/);
Answered By - WalterM
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.