简体   繁体   English

向上滚动列表视图时应用崩溃

[英]App crashes when scrolling up listview

I have an app that have listview with 15 rows.And if there is new query to search,listivew be cleaned and adds new items to listview.But after some searchings in my app and add that items to list my app is being slow and when i try to scroll up it crashes.Here is my adapter 我有一个具有15行的listview的应用程序。如果要搜索新查询,则将listivew清理并向listview添加新项目。但是在我的应用程序中进行了一些搜索并将其添加到列表中后,我的应用程序运行缓慢,何时我尝试向上滚动使其崩溃。这是我的适配器

public class VideosAdapter extends BaseAdapter {

// The list of videos to display
public static List<Video> videos;
// An inflator to use when creating rows
private LayoutInflater mInflater;
private Context context;

/**
 * @param context this is the context that the list will be shown in - used to create new list rows
 * @param videos this is a list of videos to display
 */
public VideosAdapter(Context context, List<Video> videos) {
    VideosAdapter.videos = videos;
    this.mInflater = LayoutInflater.from(context);
    this.context = context;
}

@Override
public int getCount() {
    return videos.size();
}

@Override
public Object getItem(int position) {
    return videos.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Video video = videos.get(position);

    if(video.getTitle()==null && video.getDuration()==-1)
    {
        convertView = mInflater.inflate(R.layout.more_results, null);
        View thumbnail = convertView.findViewById(R.id.thumbnail);
        thumbnail.setVisibility(View.INVISIBLE);
        return convertView;
    }
        //animation = AnimationUtils.loadAnimation(context, R.anim.push_up_in);
            // If convertView wasn't null it means we have already set it to our list_item_user_video so no need to do it again
    else if(convertView == null){
        // This is the layout we are using for each row in our list
        // anything you declare in this layout can then be referenced below
        convertView = mInflater.inflate(R.layout.list_item_user_video, null);
    }
    UrlImageView thumb = (UrlImageView) convertView.findViewById(R.id.list_image);
    //TextView size=(TextView) convertView.findViewById(R.id.size);
    TextView duration=(TextView) convertView.findViewById(R.id.duration);
    TextView title = (TextView) convertView.findViewById(R.id.userVideoTitleTextView); 


    int durationmin=video.getDuration()/60;
    int durationsec=video.getDuration()%60;

    if(durationsec<10) duration.setText(durationmin+":0"+durationsec);
    else{
        duration.setText(durationmin+":"+durationsec);
    }
     // thumb image

    // Get a single video from our list
    // Set the image for the list item
    thumb.setImageDrawable(video.getThumbUrl());
    // Set the title for the list item

    title.setText(video.getTitle());

    /*animation.setDuration(1000);
    convertView.startAnimation(animation);
    animation = null;*/

    return convertView;
}

I set adapter with this code. 我用此代码设置了适配器。

    VideosAdapter adapter = new VideosAdapter(getContext(), Allvideos);
    setAdapter(adapter);

My logcat is like this. 我的logcat就是这样。

08-22 15:53:40.557: E/InputEventReceiver(619): Exception dispatching input event.
08-22 15:53:40.657: E/AndroidRuntime(619): FATAL EXCEPTION: main
08-22 15:53:40.657: E/AndroidRuntime(619): java.lang.NullPointerException
08-22 15:53:40.657: E/AndroidRuntime(619):  at com.skymaster.tut.ui.adapter.VideosAdapter.getView(VideosAdapter.java:108)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.widget.AbsListView.obtainView(AbsListView.java:2255)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.widget.ListView.makeAndAddView(ListView.java:1769)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.widget.ListView.fillUp(ListView.java:706)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.widget.ListView.fillGap(ListView.java:645)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5040)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3197)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.widget.AbsListView.onTouchEvent(AbsListView.java:3471)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.View.dispatchTouchEvent(View.java:7127)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-22 15:53:40.657: E/AndroidRuntime(619):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
08-22 15:53:40.657: E/AndroidRuntime(619):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268)
08-22 15:53:40.657: E/AndroidRuntime(619):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.View.dispatchPointerEvent(View.java:7307)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4155)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4134)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4226)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:163)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4205)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4245)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.Choreographer.doCallbacks(Choreographer.java:555)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.Choreographer.doFrame(Choreographer.java:523)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.os.Handler.handleCallback(Handler.java:615)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.os.Looper.loop(Looper.java:137)
08-22 15:53:40.657: E/AndroidRuntime(619):  at android.app.ActivityThread.main(ActivityThread.java:4745)
08-22 15:53:40.657: E/AndroidRuntime(619):  at java.lang.reflect.Method.invokeNative(Native Method)
08-22 15:53:40.657: E/AndroidRuntime(619):  at java.lang.reflect.Method.invoke(Method.java:511)
08-22 15:53:40.657: E/AndroidRuntime(619):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-22 15:53:40.657: E/AndroidRuntime(619):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-22 15:53:40.657: E/AndroidRuntime(619):  at dalvik.system.NativeStart.main(Native Method)

As you see in my code there is URLIMAGEVIEW in my layout for each rowWith this item i load different images from url for each rows.And While image is loading spinner appears until loading be finished.Can URLIMAGEVIEW be the reason of error,or slow my app? 如您在我的代码中看到的那样,我在每行的布局中都有URLIMAGEVIEW使用此项目,我为每行从url加载了不同的图像。并且在图像加载微调器出现直到加载完成.URLIMAGEVIEW可能是错误的原因,或者减慢了我的速度应用程序吗?

EDIT:Now i posted my original logcat.And error is at this line. 编辑:现在我发布了我原来的logcat。错误在这一行。

 duration.setText(durationmin+":"+durationsec);  

Do you use notifyDataChanged() ? 您是否使用notifyDataChanged() It permit you notify the observers everytime that you have changed the content of the view, in your case everytime List videos change you have to use notifyDataChanged() . 它允许您每次更改视图内容时都通知观察者,在这种情况下,每次列表视频更改时,您都必须使用notifyDataChanged() http://developer.android.com/reference/android/widget/BaseAdapter.html#notifyDataSetChanged%28%29 . http://developer.android.com/reference/android/widget/BaseAdapter.html#notifyDataSetChanged%28%29

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM