CHarris
CHarris

Reputation: 2793

trying to start a new activity from my pop up menu

I am trying to load a new activity called Make_a_contact. The user should click on id_Admin on the pop up menu and it should load Make_a_contact.

The second menu item id_User loads the Toast part just fine.

In my build error I get:

Error:(22, 50) error: cannot find symbol variable Make_a_contact

Do you know what could be wrong?

Here's my code:

package com.example.chris.omgandroid;

import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
import android.widget.PopupMenu;
import android.widget.Toast;
import android.app.Activity;
/**
 * Created by Chris on 07/01/2016.
 */
public class PopUpMenuEventHandle extends Activity implements PopupMenu.OnMenuItemClickListener {
    Context context;
    public PopUpMenuEventHandle(Context context){
        this.context = context;
    }
    @Override
    public boolean onMenuItemClick(MenuItem item){

        if(item.getItemId()==R.id.id_Admin)
        {
            Intent intent = new Intent (context, Make_a_contact);
            startActivity(intent);
//            Toast.makeText(context, "LoginAdmin has loaded!", Toast.LENGTH_LONG).show();
//            return true;
        }

        else if(item.getItemId()==R.id.id_User){

            Toast.makeText(context, "LoginUser has loaded!", Toast.LENGTH_LONG).show();
            return true;
        }
        return false;
    }

}

Upvotes: 1

Views: 470

Answers (2)

Zack
Zack

Reputation: 145

Make_a_contact.class

should like this

Upvotes: 2

Floern
Floern

Reputation: 33904

The Intent expects the Class instance of your Activity, which you can access with the .class field:

Intent intent = new Intent(context, Make_a_contact.class);

Just providing the standalone class name Make_a_contact is invalid Java in this case.

Upvotes: 3

Related Questions