Почему getLoaderManager.initLoader () третий аргумент = это недействительно? - PullRequest
0 голосов
/ 05 июня 2019

В приложении Udacity ND..Pet, в действии, которое расширяет AppCompaActivity и реализует LoaderManager.LoaderCallbacks, вызывающий getLoaderManager.initLoader (0, null, this); выдает ошибку, что третий аргумент недействителен. *

//THESE ARE SOME OF THE IMPORT STATEMENTS;

import android.support.v4.app.LoaderManager;    
import android.support.v4.content.CursorLoader; 
import android.support.v4.content.Loader;       
import android.support.v7.app.AppCompatActivity;
public class CatalogActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {

/** Database helper that will provide us access to the database */
private PetDbHelper mDbHelper;
PetCursorAdapter mCursorAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_catalog);

    // Setup FAB to open EditorActivity
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
            @Override
        public void onClick(View view) {
            Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);
            startActivity(intent);
        }
    });
    ListView listView = (ListView) findViewById(R.id.listview);
    View emptyListView = (View) findViewById(R.id.empty_view);
    listView.setEmptyView(emptyListView);
    //mDbHelper = new PetDbHelper(this);
    mCursorAdapter = new PetCursorAdapter(this,null);
    listView.setAdapter(mCursorAdapter);
    getLoaderManager().initLoader(0,null,this);<-----HERE
    // To access our database, we instantiate our subclass of SQLiteOpenHelper
    // and pass the context, which is the current activity.
}

.... Остальная часть кода ...

BUILD.gradle file is 
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.example.pets"
    minSdkVersion 15
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-annotations:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

1 Ответ

0 голосов
/ 05 июня 2019

Просто замените ваш импорт import android.support.v4.app.LoaderManager; на import android.app.LoaderManager;

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...