Uridel
Uridel

Reputation: 69

Can't resolve symbol

So I am writing the code to make it possible to set an profile image in your application, however I get the error of being unable to resolve symbol. I don't know as to why or how.

I have commited the location where these errors occur, I am using Android Studio

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ImageButton;

import com.example.wilmar.rentacube.R;

/**
 * Created by wilmar on 23-4-2015.
 */
public class Profile extends Activity {

    ImageView contactImageImgView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile);
        String Name = getIntent().getStringExtra("Name");
        String eMail = getIntent().getStringExtra("Mail");
        String Mobile = getIntent().getStringExtra("Mobile");


        contactImageImgView = (ImageView) findViewById(R.id.imgViewContactImage);
        TextView tv_Name = (TextView) findViewById(R.id.Name);
        TextView tv_Mail = (TextView) findViewById(R.id.Email);
        TextView tv_Mobile = (TextView) findViewById(R.id.Mobile);

        tv_Name.setText(Name);
        tv_Mail.setText(eMail);
        tv_Mobile.setText(Mobile);

    }

    public void onButtonClick(View v) {
        if (v.getId() == R.id.BeditProfile) {
            Intent i = new Intent(Profile.this, editProfile.class);
            startActivity(i);
        }

    }

    contactImageImgView.setOnClickListener(new View.OnClickListener) //error @.setOnClickListener Cannot resolve symbol
    {
        public void onClick (View v){  // error @ View v, cannot resolve symbol v , expected ;
        Intent intent = new Intent();
        intent.setType("image*/");
        intent.setAction(intent.ACTION_GET_CONTENT);
        startActivityForResult(intent.createChooser(intent, "Select Profile Image"), 1);
        }
    }

    public void onActivityResult(int reqCode, int resCode, Intent data) {
        if(resCode == RESULT_OK){
            if(resCode == 1)
                contactImageImgView.setImageURI(data.getData());
        }

    }


}

Upvotes: 0

Views: 6177

Answers (3)

Manish
Manish

Reputation: 740

You have misplaced the braces in the setOnClickListener. You are supposed to create an inner class in the argument to this method. Use it in this way

contactImageImgView.setOnClickListener(new View.OnClickListener()
    {
        public void onClick (View v){  // error @ View v, cannot resolve symbol v , expected ;
        Intent intent = new Intent();
        intent.setType("image*/");
        intent.setAction(intent.ACTION_GET_CONTENT);
        startActivityForResult(intent.createChooser(intent, "Select Profile Image"), 1);
        }
    });

Upvotes: 0

Fouad Wahabi
Fouad Wahabi

Reputation: 804

You're making a syntax error in implementing the View.OnClickListener anonymous object, the right one is :

contactImageImgView.setOnClickListener(new View.OnClickListener() {

        public void onClick (View v){  // error @ View v, cannot resolve symbol v , expected ;
        Intent intent = new Intent();
        intent.setType("image*/");
        intent.setAction(intent.ACTION_GET_CONTENT);
        startActivityForResult(intent.createChooser(intent, "Select Profile Image"), 1);
        }
    });

Upvotes: 0

Exception
Exception

Reputation: 2323

contactImageImgView.setOnClickListener(new View.OnClickListener) //error @.setOnClickListener Cannot resolve symbol
{
    public void onClick (View v){  // error @ View v, cannot resolve symbol v , expected ;
    Intent intent = new Intent();
    intent.setType("image*/");
    intent.setAction(intent.ACTION_GET_CONTENT);
    startActivityForResult(intent.createChooser(intent, "Select Profile Image"), 1);
    }
}

The above code needs to be inside a method. Put it inside onCreate(), and it will work.

Upvotes: 2

Related Questions