简体   繁体   English

LoaderManager尚未初始化... getLoaderManager()。initLoader出现问题

[英]LoaderManager not initializing… a issue with getLoaderManager().initLoader

I know there is a lot of common questions like this out there but I just can't seem to find the solution. 我知道这里有很多类似的常见问题,但我似乎找不到解决方法。 When I attempt to initialize my loader using getLoaderManager().initLoader(LOADER_ID, null, this); 当我尝试使用getLoaderManager().initLoader(LOADER_ID, null, this);初始化加载器时getLoaderManager().initLoader(LOADER_ID, null, this); The error The method initLoader(int, Bundle, LoaderManager.LoaderCallbacks) in the type LoaderManager is not applicable for the arguments (int, null, Gridview) comes up. 错误类型为LoaderManager的方法initLoader(int,Bundle,LoaderManager.LoaderCallbacks)不适用于出现的参数(int,null,Gridview)。

This leads me to believe that the program is not recognizing that Gridview implements the loader manager. 这使我相信该程序无法识别Gridview实现了加载程序管理器。 I'm not sure why this is and where to go from here. 我不确定为什么会这样,以及从这里去哪里。 I tried playing around with different imports but that didn't work. 我尝试使用不同的进口货,但这没用。 I also made sure I had the proper downloads to support loaders. 我还确保我有正确的下载来支持加载程序。 The code I am using is below. 我正在使用的代码如下。

package com.example.camerapreview;

import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;

//Omissis imports


public class Gridview extends Activity implements LoaderManager.LoaderCallbacks<Cursor>{       
    private static final String TAG = "Checking Database";
    private static final String TAG1 = "Checking Thumbnail";

    Cursor cursor;
    int columnindexid;
    int columnindexdata;
    int videoidindex;
    int videopathindex;
    GridviewData entry;
    GridView gridview;
    VideoAdapter videoadapter;
    Cursor curs;

    ImageLoaderConfiguration config;

    String[] mediaColumns = {
        MediaStore.Video.Media._ID,
        MediaStore.Video.Media.DATA,
        MediaStore.Video.Media.TITLE,
        MediaStore.Video.Media.MIME_TYPE
    };

    private static final int LOADER_ID = 1;
    int flags = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.preview);
        gridview = (GridView) this.findViewById(R.id.gridview);


        cursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, mediaColumns, null, null, null);
        columnindexid = cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID);
        columnindexdata = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);

        entry = new GridviewData(this);
        entry.open();

        getLoaderManager().initLoader(LOADER_ID, null, this);
        DataEntry putitin = new DataEntry(entry, this);
        putitin.execute();

        //the cursor used in the cursor adapater
        curs = entry.adapterCursor();
        videoidindex = entry.Indexfinder(curs);
        videopathindex = entry.Indexfinder2(curs);

        config = new ImageLoaderConfiguration.Builder(this)
                        .imageDownloader(new BaseImageDownloader(this))
                        .build();

        ImageLoader.getInstance().init(config);
        Log.i(TAG, "Before set adapater");
        gridview.setAdapter(new VideoAdapter(this, curs, flags));
     }
}

EDIT: 编辑:

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String[] projection = { GridviewData.VIDEOID, GridviewData.VIDEOFILEPATH };
    return new CursorLoader(Gridview.this, MyContentProvider.CONTENT_URI, projection, null, null, null);
}

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
    cursoradapter.swapCursor(c);
}

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    cursoradapter.swapCursor(null);     
}

The error is caused by your imports: 该错误是由您的导入引起的:

import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;

they would be fine for FragmentActivity but you are using a normal Activity so they should be: 它们对于FragmentActivity来说很好,但是您使用的是正常的Activity因此它们应该是:

import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.CursorLoader;
import android.content.Loader;
import android.widget.CursorAdapter;

Please note that in this case your android:minSdkVersion should be 11. If you need compatibility with lower versions, just keep the imports as they are and use FragmentActivity . 请注意,在这种情况下,您的android:minSdkVersion应该为11。如果您需要与较低版本兼容,只需保持导入不变并使用FragmentActivity

暂无
暂无

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

相关问题 尽管类 (ListFragment) 实现了 LoaderManager.LoaderCallbacks,但 getLoaderManager().initLoader() 不接受“this”作为参数<Cursor> - getLoaderManager().initLoader() doesn't accept 'this' as argument though the class (ListFragment) implements LoaderManager.LoaderCallbacks<Cursor> 此回调中的 getLoaderManager().initLoader 错误 - getLoaderManager().initLoader error in this callback getLoaderManager()。initLoader(0,null,this); //错误“ this”被加红线 - getLoaderManager().initLoader(0, null, this);//error “this” is redlined getLoaderManager()的args参数的用途.initLoader(...,...,...)? - Purpose of args parameter of getLoaderManager().initLoader(…,…,…)? 用 MutableLivedata 替换 getLoaderManager().initLoader<Cursor> - Replace getLoaderManager().initLoader with MutableLivedata<Cursor> LoaderManager中initLoader和restartLoader的区别 - Difference between initLoader and restartLoader in LoaderManager getLoaderManager.initLoader出现刺激性错误 - Got irritating error with getLoaderManager.initLoader 可以两次调用getLoaderManager()。initLoader - is possible call getLoaderManager().initLoader two times 为什么getLoaderManager.initLoader()第三个参数=这是无效的? - Why getLoaderManager.initLoader() third argument = this IS INVALID? 不能在 getLoaderManager().initLoader() 方法中使用“this”作为参数 - Can't use "this" as an argument in the getLoaderManager().initLoader() method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM