Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AndroidAnnotations@EBean类实例化问题_Android_Android Annotations - Fatal编程技术网

AndroidAnnotations@EBean类实例化问题

AndroidAnnotations@EBean类实例化问题,android,android-annotations,Android,Android Annotations,我正在使用AA实现我自己的适配器类扩展BaseAdapter,但是我需要构造函数中的多个参数来正确实例化它。我想知道有没有办法 @EBean public class MomentViewAdapter extends BaseAdapter { protected LayoutInflater mInflater; protected Context mContext; protected List<FavoriteInfo> mDatas; pro

我正在使用AA实现我自己的适配器类扩展BaseAdapter,但是我需要构造函数中的多个参数来正确实例化它。我想知道有没有办法

@EBean
public class MomentViewAdapter extends BaseAdapter {
    protected LayoutInflater mInflater;
    protected Context mContext;
    protected List<FavoriteInfo> mDatas;
    protected  int mItemLayoutId;

    public MomentViewAdapter(Context context) {
        this.mContext = context;
//        this.mInflater = LayoutInflater.from(mContext);
//        this.mDatas = mDatas;
//        this.mItemLayoutId = itemLayoutId;
    }

    public void setUp(List<FavoriteInfo> mDatas, int itemLayoutId) {
        this.mInflater = LayoutInflater.from(mContext);
        this.mDatas = mDatas;
        this.mItemLayoutId = itemLayoutId;
    }


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

    @Override
    public FavoriteInfo getItem(int position)
    {
        return mDatas.get(position);
    }

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

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

        if(convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(mItemLayoutId, parent, false);
        }
        ImageView img = (ImageView) convertView.findViewById(R.id.detail_moment_camera_picture);
        if (mDatas.get(position).isVideoFavorite()) {
            Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(mDatas.get(position).getVideoURL(), MediaStore.Video.Thumbnails.MINI_KIND);
            img.setImageBitmap(bitmap);
        } else {
            getBitmapFromURL(mDatas.get(position).getImageURL(), img);
            // img.setImageBitmap(getBitmapFromURL(mDatas.get(position).getImageURL()));
        }
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, GeneratedClassUtils.get(MomentDetailActivity.class));
                Bundle mBundle = new Bundle();
                mBundle.putSerializable(FavoriteInfo.KEY, mDatas.get(position));
                mBundle.putBoolean(CollectionInfo.KEY_WATCH_FLAG, false);
                intent.putExtras(mBundle);
                mContext.startActivity(intent);
            }
        });

        return convertView;

    }

    @Background
    protected void getBitmapFromURL(String src, ImageView img) {
        try {
            URL url = new URL(src);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            updateImageView(BitmapFactory.decodeStream(input), img);
            return;
        } catch (IOException e) {
            System.out.println("************** network exception: download image failed");
            return;
        }
    }

    @UiThread
    protected void updateImageView(Bitmap bitmap, ImageView img) {
        img.setImageBitmap(bitmap);
        return;
    }

}
当我在手机上运行它时,出现空指针异常:

unable to start activity ComponentInfo{com.bloomsky.bloomsky/com.bloomsky.android.activities.common.DeviceDetailActivity_}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.GridView.setAdapter(android.widget.ListAdapter)' on a null object reference

它出现在setUp()方法被调用之后,这让我很困惑。因此,我认为可能对象没有正确实例化。

mGridView
为空,因为
@AfterInject
@afterview
之前调用。您的视图还没有受到Android注释的约束。因此,请改用
@afterview

请发布完整的代码。将适配器设置为网格视图时会发生异常,但问题不包含该代码。
unable to start activity ComponentInfo{com.bloomsky.bloomsky/com.bloomsky.android.activities.common.DeviceDetailActivity_}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.GridView.setAdapter(android.widget.ListAdapter)' on a null object reference