Minho
Minho

Reputation: 927

Creating new activity in android

    happyButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent response = new Intent(this, UserResponse.class);
            startActivity(response);

        };


    });

There's an error in the line (this, UserResponse.class); even after I created a new class called UserResponse.

Upvotes: 2

Views: 41

Answers (3)

Robinhiio
Robinhiio

Reputation: 105

Its because you use .this in an onClicklistener change it to getApplicaton()

Upvotes: 0

A. Wali
A. Wali

Reputation: 454

If you had created the class manually, Check for two things:

  1. UserResponse class extends Activity

  2. The Activity is included in the Manifest

It should be something like this

<activity 
    android:name="UserResponse" 
    android:label="@string/User_Response">
</activity>

Also change the intent as Guilherme P has suggested

Upvotes: 2

guipivoto
guipivoto

Reputation: 18687

Change

Intent response = new Intent(this, UserResponse.class);

To

Intent response = new Intent(MainActivity.this, UserResponse.class);

Replace the MainActivity by the name of your current activity (current.. not target activity)

Upvotes: 4

Related Questions