因此,我正在编写代码,以便可以在您的应用程序中设置配置文件图像,但是却出现无法解析符号的错误。我不知道为什么或如何。
我已经提交了发生这些错误的位置,我正在使用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());
}
}
}
最佳答案
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);
}
}
上面的代码需要在方法内部。将其放在
onCreate()
中,它将起作用。