Android java.lang.IllegalArgumentException:Path不能为空

时间:2016-08-06 09:01:56

标签: java android path illegalargumentexception

Android java.lang.IllegalArgumentException:路径不能为空。怎么解决?我想找到联系人的照片。应用程序不断崩溃。我不知道如何解决它。试过谷歌但仍然无法解决此错误。没有照片设置的联系人工作正常。只有那些设置了照片的联系人才会出错。

代码:

   @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final Contact c = filtered_items.get(position);
        holder.name.setText(c.name);
      // if(c.photoUri.equals("")){
        if(c.photoUri == null && c!=null){
            holder.image.setImageResource(R.drawable.unknown_avatar);
        }else{

            Picasso.with(ctx).load(c.photoUri)
                    .resize(100, 100)
                    .transform(new CircleTransform())
                    .into(holder.image);
        }
        holder.lyt_parent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogAbout(c);
            }
        });

    }

日志:

`FATAL EXCEPTION: main
Process: com.example.apple.qs, PID: 32061
java.lang.IllegalArgumentException: Path must not be empty.
at com.squareup.picasso.Picasso.load(Picasso.java:181)
at com.example.apple.qs.Activity.adapter.ContactListAdapter.onBindViewHolder(ContactListAdapter.java:92)
at com.example.apple.qs.Activity.adapter.ContactListAdapter.onBindViewHolder(ContactListAdapter.java:31)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5471)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5504)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4741)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)    at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1077)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:122)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1170)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:814)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16672)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2032)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1191)
at android.view.ViewRootImpl$TraversalRun`

4 个答案:

答案 0 :(得分:0)

在通过毕加索之前检查你的路径是否为空

if(c.photoUri != null && !c.photoUri.isEmpty())
{
Picasso.with(ctx).load(c.photoUri)
                .resize(100, 100)
                .transform(new CircleTransform())
                .into(holder.image);  
 }

答案 1 :(得分:0)

即使你使用.error(R.drawable.image),毕加索也会失败,这很奇怪。要解决此问题,您应手动检查字符串空白,如果配置文件照片的路径为空,则放置一些默认占位符:

if (c.photoUri != null && c.photoUri.isEmpty()) {
   iview.setImageResource(R.drawable.placeholder);
} else {
    Picasso.with(this).load(c.photoUri)
            .placeholder(R.drawable.avatar_gray)
            .error(R.drawable.avatar_gray)
            .into(holder.image);
}

答案 2 :(得分:0)

确保图片网址不为空。特别是在从firebase引用时。

eventAfterRender: function(event, element) {
    var $element = element.find('.fc-time');
    if ($element.length > 0) {
        return;
    }
    var $content = element.find('.fc-content');
    $content.prepend('<div class="fc-time" data-start="12:00" data-full="12:00 AM - 6:00 AM" style="margin-right: 2px; background-color: rebeccapurple;"><span>12:00 - 6:00</span></div>');


  }

答案 3 :(得分:0)

确保提供正确的Firebase存储路径和正确的存储参考。

代码:

StorageReference storageReference = FirebaseStorage.getInstance()
    .getReference()
    .child("storage_path");