该应用程序崩溃使用毕加索和发送空白图片

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了该应用程序崩溃使用毕加索和发送空白图片相关的知识,希望对你有一定的参考价值。

我正在使用毕加索作为我的导航抽屉档案图片。

一旦我点击导航抽屉中的显示图片,应用程序就会崩溃。但是,当事先在此处上传图片时,它可以正常工作,点击它可以显示来自后端的完整用户配置文件。

我的代码是:

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 ComponentInfoin.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:路径不能留空。

我在几个地方读到毕加索无法处理空地址。有人可以告诉我如何解决这个问题。

答案

对于毕加索的旧版本:

试试这个

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);

另一答案

试试这种方式

if(!TextUtils.isEmpty(data.getImageUrl())) 
                        Picasso.with(data.getImageUrl())
                                .load(R.drawable.ic_user)
                                .into(civProfileImage);
                    
另一答案

毕加索不允许你设置空路径。从您的Logcat:

 Caused by: java.lang.IllegalArgumentException: Path must not be empty

检查答案here

另一答案

添加其他答案,Picasso允许您管理下载错误

Picasso.error(DEFAULT IMAGE);
另一答案

试试这个

 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);
    

以上是关于该应用程序崩溃使用毕加索和发送空白图片的主要内容,如果未能解决你的问题,请参考以下文章

升级毕加索库时 Android 崩溃

片段中的Android webView显示空白页面

底部导航片段应用程序不断崩溃

毕加索没有在我的 ImageView 中显示图片我该怎么办?

使用选项卡式活动和片段时应用程序崩溃

从片段内请求权限后应用程序崩溃