我正在使用毕加索作为我的导航抽屉档案图片。
点击导航栏中的显示图片后,应用程序崩溃了。 但是,当事先在此处上传图片时,它可以正常工作,点击它可以显示来自后端的完整用户配置文件。
我的代码是:
public class ProfileActivity extends BaseActivity {
@InjectView(R.id.svParent)
ScrollView svParent;
@InjectView(R.id.toolbar)
Toolbar mToolbar;
@InjectView(R.id.action_title)
TextView tvActionTitle;
@InjectView(R.id.civProfileImage)
CircleImageView civProfileImage;
@InjectView(R.id.tvName)
TextView tvName;
@InjectView(R.id.tvCity)
TextView tvCity;
@InjectView(R.id.etEmail)
EditText etEmail;
@InjectView(R.id.etPhoneNumber)
EditText etPhoneNumber;
@InjectView(R.id.etAlternatePhoneNumber)
EditText etAlternatePhoneNumber;
@InjectView(R.id.etAddress)
EditText etAddress;
@InjectView(R.id.etDescription)
EditText etDescription;
@InjectView(R.id.llProgressContainer)
LinearLayout llProgressContainer;
public static Intent callingIntent(Context context) {
return new Intent(context, ProfileActivity.class);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
ButterKnife.inject(this);
setParentView(svParent);
setActionBar();
initUserProfile();
}
private void setActionBar() {
setSupportActionBar(mToolbar);
ActionBar supportActionBar = getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setTitle("");
supportActionBar.setDisplayHomeAsUpEnabled(true);
}
tvActionTitle.setText(getResources().getString(R.string.label_user_profile));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void initUserProfile() {
String prefsData = SharedPrefsManager.getUserData(getApplicationContext());
UserData userData = new Gson().fromJson(prefsData, UserData.class);
Data data = userData.getData();
if (data != null) {
String name = data.getName();
String city = data.getCity();
String mobile = data.getMobile();
String alternateMobile = data.getAlternateMobile();
String mail = data.getEmail();
String address = data.getAddress();
if (!TextUtils.isEmpty(name)) {
tvName.setText(name);
} else {
tvName.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(city)) {
tvCity.setText(city);
} else {
tvCity.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(mobile)) {
etPhoneNumber.setText(mobile);
etPhoneNumber.setEnabled(false);
} else {
etPhoneNumber.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(alternateMobile)) {
etAlternatePhoneNumber.setText(alternateMobile);
etAlternatePhoneNumber.setEnabled(false);
} else {
etAlternatePhoneNumber.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(mail)) {
etEmail.setText(mail);
etEmail.setEnabled(false);
} else {
etEmail.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(address)) {
etAddress.setText(address);
etAddress.setEnabled(false);
} else {
etAddress.setVisibility(View.GONE);
}
Picasso.with(getApplicationContext())
.load(!TextUtils.isEmpty(data.getImageUrl()) ? APIMethods.LIVE_SERVER + data.getImageUrl() : "")
.placeholder(R.drawable.ic_user)
.into(civProfileImage);
}
}
}
弹出的例外情况是:
07-18 08:40:31.268 8668-8668/in.mahabir E/AndroidRuntime: FATAL EXCEPTION: main
Process: in.mahabir, PID: 8668
java.lang.RuntimeException: Unable to start activity ComponentInfo{in.mahabir/in.mahabir.ui.profile.ProfileActivity}: java.lang.IllegalArgumentException: Path must not be empty.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalArgumentException: Path must not be empty.
at com.squareup.picasso.Picasso.load(Picasso.java:194)
at in.mahabir.ui.profile.ProfileActivity.initUserProfile(ProfileActivity.java:154)
at in.mahabir.ui.profile.ProfileActivity.onCreate(ProfileActivity.java:78)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
基本上是IllegalArgumentException:路径不能留空。
我在一些地方读到毕加索无法处理空地址。有人可以告诉我如何解决这个问题。
答案 0 :(得分:0)
试试这个
if (!TextUtils.isEmpty(data.getImageUrl())) {
Picasso.get()
.load(!TextUtils.isEmpty(data.getImageUrl()) ? APIMethods.LIVE_SERVER + data.getImageUrl() : "")
.placeholder(R.drawable.ic_user)
.into(civProfileImage);
} else {
civProfileImage.setimageResource(R.mipmap.ic_launcer);
}
答案 1 :(得分:0)
适用于毕加索的旧版本:
试试这个
Picasso.with(getApplicationContext())
.load(!TextUtils.isEmpty(data.getImageUrl()) ? APIMethods.LIVE_SERVER + data.getImageUrl() : R.drawable.ic_user)
.placeholder(R.drawable.ic_user)
.into(civProfileImage);
或者这个
try{
Picasso.with(getApplicationContext())
.load(APIMethods.LIVE_SERVER + data.getImageUrl())
.placeholder(R.drawable.ic_user)
.into(civProfileImage);
}catch (Exception e){
e.printStackTrace();
Picasso.with(getApplicationContext())
.load(R.drawable.ic_user)
.into(civProfileImage);
}
新版毕加索:
试试这个
Picasso.get()
.load(!TextUtils.isEmpty(data.getImageUrl()) ? APIMethods.LIVE_SERVER + data.getImageUrl() : R.drawable.ic_user)
.placeholder(R.drawable.ic_user)
.into(civProfileImage);
或者这个
try{
Picasso.get()
.load(APIMethods.LIVE_SERVER + data.getImageUrl())
.placeholder(R.drawable.ic_user)
.into(civProfileImage);
}catch (Exception e){
e.printStackTrace();
Picasso.get()
.load(R.drawable.ic_user)
.into(civProfileImage);
}
答案 2 :(得分:0)
以这种方式尝试
if(!TextUtils.isEmpty(data.getImageUrl())) {
Picasso.with(data.getImageUrl())
.load(R.drawable.ic_user)
.into(civProfileImage);
}
答案 3 :(得分:0)
Picasso不允许你设置空路径。来自您的Logcat:
Caused by: java.lang.IllegalArgumentException: Path must not be empty
检查答案here
答案 4 :(得分:0)
添加其他答案,Picasso允许您使用
管理下载错误Picasso.error(DEFAULT IMAGE);