我一直在尝试使用json将数据放入列表

时间:2018-10-10 14:21:06

标签: android

am使用Picasso库获取图像URL,但随后该应用程序停止了。这是我的错误日志和listAdapter的示例

@Override
    public View getView(int position,  View convertView,  ViewGroup parent) {
        final View result;

        ViewHolder holder;
        if ( convertView == null ) {
            LayoutInflater inflater=LayoutInflater.from ( mCtx );

            convertView=inflater.inflate ( R.layout.listtips , null , true );
            holder=new ViewHolder ();
            holder.time=(TextView) convertView.findViewById ( R.id.time );
            holder.input=(TextView) convertView.findViewById ( R.id.input );

            holder.match=(TextView) convertView.findViewById ( R.id.match );
            holder.bookies=(TextView) convertView.findViewById ( R.id.bookies );
            holder.predict=(TextView) convertView.findViewById ( R.id.predict );
            holder.results=(TextView) convertView.findViewById ( R.id.results );
            holder.imgURl=(ImageView) convertView.findViewById ( R.id.image ) ;





            result=convertView;

            convertView.setTag ( holder );
        } else {
            holder=(ViewHolder) convertView.getTag ();
            result=convertView;
        }

        Animation animation=AnimationUtils.loadAnimation ( mCtx , (position > lastPosition) ? R.anim.load_down_anim : R.anim.load_up_anim );
        result.startAnimation ( animation );
        lastPosition=position;

        tips tips=tipsList.get ( position );
        holder.time.setText ( tips.getTime () );

        holder.input.setText ( tips.getInput () );

        holder.match.setText ( tips.getMatch () );
        holder.bookies.tip.setText ( tips.getBookies () );
        holder.predict.setText ( tips.getPredict () );
        holder.results.setText ( tips.getResults () );

        Picasso.with(mCtx).load(tips.getStatus ()).into(holder.imgURl);

            return convertView;
        }

Logcat:

10-10 16:37:42.118 10295-10295/com.example.kim.tipsscore E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.IllegalArgumentException: Path must not be empty.
        at com.squareup.picasso.Picasso.load(Picasso.java:297)
        at com.example.kim.tipsscore.Adapter.TipsAdapter.getView(TipsAdapter.java:106)
        at android.widget.AbsListView.obtainView(AbsListView.java:2603)
        at android.widget.ListView.makeAndAddView(ListView.java:1840)
        at android.widget.ListView.fillDown(ListView.java:681)
        at android.widget.ListView.fillFromTop(ListView.java:742)
        at android.widget.ListView.layoutChildren(ListView.java:1661)
        at android.widget.AbsListView.onLayout(AbsListView.java:2426)
        at android.view.View.layout(View.java:14905)
        at android.view.ViewGroup.layout(ViewGroup.java:4601)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1694)
        at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1683)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1467)
        at android.view.View.layout(View.java:14905)
        at android.view.ViewGroup.layout(ViewGroup.java:4601)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
        at android.view.View.layout(View.java:14905)
        at android.view.ViewGroup.layout(ViewGroup.java:4601)
        at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:443)
        at android.view.View.layout(View.java:14905)
        at android.view.ViewGroup.layout(ViewGroup.java:4601)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
        at android.view.View.layout(View.java:14905)
        at android.view.ViewGroup.layout(ViewGroup.java:4601)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1694)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1552)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
        at android.view.View.layout(View.java:14905)
        at android.view.ViewGroup.layout(ViewGroup.java:4601)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
        at android.view.View.layout(View.java:14905)
        at android.view.ViewGroup.layout(ViewGroup.java:4601)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2213)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2027)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1237)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5162)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
        at android.view.Choreographer.doCallbacks(Choreographer.java:591)
        at android.view.Choreographer.doFrame(Choreographer.java:561)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:5317)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
        at dalvik.system.NativeStart.main(Native Method) 10-10 16:37:45.972 10295-10295/com.example.kim.tipsscore I/Process: Sending signal. PID: 10295 SIG: 9

1 个答案:

答案 0 :(得分:1)

错误很明显

  

路径不能为空。在com.squareup.picasso.Picasso.load

tips.getStatus()中的含义Picasso.with(mCtx).load(tips.getStatus ())为空或空白

解决方案:确保getStatus返回默认值,如果空白

(您可以使用lang3库StringUtils.isBlank()