Ryan Sangha
Ryan Sangha

Reputation: 461

Android error on activity start

I don't know why I get an error on the name FirstActivity?

public class FirstActivity extends Activity {

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.onStart();
    TextView tv = new TextView(this);
    tv.setText("Hello, Android");
    setContentView(tv);
           }
        }

Upvotes: 0

Views: 1934

Answers (3)

Agnihotri.
Agnihotri.

Reputation: 426

Remove super.onStart() from your code.

And this link will help you.

http://developer.android.com/reference/android/app/Activity.html

Upvotes: 1

SPie
SPie

Reputation: 174

It would be helpful to know what error you've got, but I think the problem is the

super.onStart();

line in your code.

onStart() would be called by the activity after onCreate() and you dont have to call it by yourself (Source).

Upvotes: 2

Raghav Sood
Raghav Sood

Reputation: 82533

There are a few errors in your code:

public class FirstActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView tv = new TextView(this);
    tv.setText("Hello, Android");
    setContentView(tv);
  }
}

You do not need to call super.onStart() in onCreate().

Other than that, your error could be because you have a mismatched constructor somewhere (Activities to need need constructors), or because your .java file has a different name.

Upvotes: 0

Related Questions