it-swarm.com.de

java.lang.NoClassDefFoundError: Fehler bei der Auflösung von: Landroidx/core/app/ActivityManagerCompat

Beschreibung


Ich möchte todolist app erstellen. Ich möchte Informationen mit RoomDatabse ..__ speichern. Ich errichte Datenbank mit Platz und erhalte Informationen als Speichern in Datenbank . Aber wenn ich auf "Hinzufügen" klicke, bekam ich die Ausnahme ..__ Ich habe über das Web nach einer geeigneten Lösung gesucht, aber nichts Nützliches gefunden. Bitte helfen Sie mir.

Meine ausnahme

 Caused by: Java.lang.ClassNotFoundException: Didn't find class
"androidx.core.app.ActivityManagerCompat" while store data using Room.

Meine Android Studio-Konfiguration

compileSdkVersion 27
buildToolsVersion '28.0.3'
minSdkVersion 15
targetSdkVersion 27

Meine Datenbankklasse

@Database(entities = {TaskEntry.class},version = 1,exportSchema = false)

@TypeConverters (DateConverter.class) Die öffentliche abstrakte Klasse AppDatabase erweitert RoomDatabase {

private static final String LOG_TAG=AppDatabase.class.getSimpleName();
private static final Object LOCK=new Object();
private static final String DATABASE_NAME="todolist";
private static AppDatabase mInstance;

public static AppDatabase getInstance(Context context){

    if(mInstance==null){
        synchronized (LOCK){
            Log.d(LOG_TAG,"Creating new database instance");
            mInstance= Room.databaseBuilder(context.getApplicationContext(),
                    AppDatabase.class,AppDatabase.DATABASE_NAME)
                    .allowMainThreadQueries()
                    .build();
        }
    }
    Log.d(LOG_TAG,"getting the database instance");
    return mInstance;

}

public abstract TaskDao taskDao();

}

Mein AddTaskActivity-Code

public class AddTaskActivity extends AppCompatActivity {

// Extra for the task ID to be received in the intent
public static final String EXTRA_TASK_ID = "extraTaskId";
// Extra for the task ID to be received after rotation
public static final String INSTANCE_TASK_ID = "instanceTaskId";
// Constants for priority
public static final int PRIORITY_HIGH = 1;
public static final int PRIORITY_MEDIUM = 2;
public static final int PRIORITY_LOW = 3;
// Constant for default task id to be used when not in update mode
private static final int DEFAULT_TASK_ID = -1;
// Constant for logging
private static final String TAG = AddTaskActivity.class.getSimpleName();
// Fields for views
EditText mEditText;
RadioGroup mRadioGroup;
Button mButton;

private int mTaskId = DEFAULT_TASK_ID;
private AppDatabase mDb;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_task);
    mDb=AppDatabase.getInstance(getApplicationContext());

    initViews();

    if (savedInstanceState != null && savedInstanceState.containsKey(INSTANCE_TASK_ID)) {
        mTaskId = savedInstanceState.getInt(INSTANCE_TASK_ID, DEFAULT_TASK_ID);
    }

    Intent intent = getIntent();
    if (intent != null && intent.hasExtra(EXTRA_TASK_ID)) {
        mButton.setText(R.string.update_button);
        if (mTaskId == DEFAULT_TASK_ID) {
            // populate the UI
        }
    }
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putInt(INSTANCE_TASK_ID, mTaskId);
    super.onSaveInstanceState(outState);
}

/**
 * initViews is called from onCreate to init the member variable views
 */
private void initViews() {
    mEditText = findViewById(R.id.editTextTaskDescription);
    mRadioGroup = findViewById(R.id.radioGroup);

    mButton = findViewById(R.id.saveButton);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onSaveButtonClicked();
        }
    });
}

/**
 * populateUI would be called to populate the UI when in update mode
 *
 * @param task the taskEntry to populate the UI
 */
private void populateUI(TaskEntry task) {

}

/**
 * onSaveButtonClicked is called when the "save" button is clicked.
 * It retrieves user input and inserts that new task data into the underlying database.
 */
public void onSaveButtonClicked() {
    // Not yet implemented
    String description=mEditText.getText().toString();
    int priority=getPriorityFromViews();
    Date date=new Date();
    TaskEntry taskEntry=new TaskEntry(description,priority,date);
    mDb.taskDao().insertTask(taskEntry);
    finish();
}

/**
 * getPriority is called whenever the selected priority needs to be retrieved
 */
public int getPriorityFromViews() {
    int priority = 1;
    int checkedId = ((RadioGroup) findViewById(R.id.radioGroup)).getCheckedRadioButtonId();
    switch (checkedId) {
        case R.id.radButton1:
            priority = PRIORITY_HIGH;
            break;
        case R.id.radButton2:
            priority = PRIORITY_MEDIUM;
            break;
        case R.id.radButton3:
            priority = PRIORITY_LOW;
    }
    return priority;
}

/**
 * setPriority is called when we receive a task from MainActivity
 *
 * @param priority the priority value
 */
public void setPriorityInViews(int priority) {
    switch (priority) {
        case PRIORITY_HIGH:
            ((RadioGroup) findViewById(R.id.radioGroup)).check(R.id.radButton1);
            break;
        case PRIORITY_MEDIUM:
            ((RadioGroup) findViewById(R.id.radioGroup)).check(R.id.radButton2);
            break;
        case PRIORITY_LOW:
            ((RadioGroup) findViewById(R.id.radioGroup)).check(R.id.radButton3);
    }
}

}

3
Rabbi hasan

Verwenden Sie das in Ihren gradle Abhängigkeiten?

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

Wenn ja, ersetzen Sie es durch:

    implementation 'Android.Arch.persistence.room:runtime:1.1.1'
    annotationProcessor 'Android.Arch.persistence.room:compiler:1.1.1'
3
Rb87

Versuchen Sie, das Projekt gemäß den unter " https://developer.Android.com/jetpack/androidx/migrate " angegebenen Schritten auf AndroidX zu migrieren.

Ändern Sie vorhandene Paket- und Klassennamen in die im Unterabschnitt " https://developer.Android.com/jetpack/androidx/migrate#artifact_mappings " angegebenen.

0
Vaibhav

sie könnten die Abhängigkeit vermissen ...

 androidx.core:core:1.0.0

was androidx.core.app.ActivityManagerCompat liefert.

0
Martin Zeitler