Reputation: 19
I'm trying to produce several buttons which open different links but by copying the file over I get an error saying onCreate(Bundle) is already defined? Is it because I have two protected void onCreate(Bundle savedInstanceState) {
or something? Please add a description to what is the issue and possibly an answer.
package saintbedeslytham.saintbedes;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class news extends ActionBarActivity {
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent NameOfTheIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.st-bedes-high.lancsngfl.ac.uk/getfile.php?src=742/Christmas+Newsletter+2014.pdf"));
startActivity(NameOfTheIntent);
}
});
}
Button button2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news);
button1 = (Button)findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent NameOfTheIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.st-bedes-high.lancsngfl.ac.uk/getfile.php?src=742/Christmas+Newsletter+2014.pdf"));
startActivity(NameOfTheIntent);
}});
}}
Upvotes: 0
Views: 1482
Reputation: 30601
You have defined the same method onCreate()
twice. In Java, two methods cannot have the same name and the same parameter list. If you like, name the second method as
public void onCreate2(Bundle savedInstanceState){}
or something like that.
Upvotes: 2