JZVideo Error: Attempt to invoke virtual method ‘android.view.Window android.app.Activity.getWindow()’ on a null object reference

1. Error reporting

Attempt to invoke virtual method ‘android.view.Window android.app.Activity.getWindow()’ on a null object reference

2. Cause

VideoAdapter.java file code:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_mainlv,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        // Get the data source of the specified location
        String path = "xxxx";
        holder.jzvdStd.setUp(path,"test",JzvdStd.SCREEN_NORMAL);

        holder.jzvdStd.positionInList = position;

        return convertView;
    }

    class ViewHolder{
        JzvdStd jzvdStd;
        public ViewHolder(View view){
            jzvdStd = view.findViewById(R.id.item_main_jzvd);
        }
    }

Since jzvdStd has released the jzvdStd window when the full screen is cut to a small screen, and the subsequent if (convertView == null) judgment, directly to the else statement, so the window that has been released cannot be obtained by the statement in the else in the window, so the error is reported. (The above is a personal opinion)

3. Solution

Replace the above code with the following code

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

        ViewHolder viewHolder;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            LayoutInflater mInflater = LayoutInflater.from(context);
            convertView = mInflater.inflate(R.layout.item_mainlv, null);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.jzvdStd = convertView.findViewById(R.id.item_main_jzvd);


        // Get the data source of the specified location
        String path = "xxx";
        viewHolder.jzvdStd.setUp(path,"test",JzvdStd.SCREEN_NORMAL);

        return convertView;
    }

    class ViewHolder{
        JzvdStd jzvdStd;
    }

Read More: