| Android apps help [message #1006866] |
Sat, 02 February 2013 23:05  |
Tyler Mayoff Messages: 2 Registered: February 2013 |
Junior Member |
|
|
Hello,
I'm just experimenting with making apps on android and decided to start simple with making a button. I have encountered a problem with the code.
package com.example.minecraftcrafting;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "You pressed button", Toast.LENGTH_SHORT);
}
}) <-------- Red underline
}
}
When I do what it tells me I get this
package com.example.minecraftcrafting;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() { <--- Whole line Red underlined
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "You pressed button", Toast.LENGTH_SHORT);
}
})
}
}
I am very new to this so can you please go easy on me.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02991 seconds