简体   繁体   English

java.lang.NoClassDefFoundError:解析失败:Landroidx / core / app / ActivityManagerCompat

[英]java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/ActivityManagerCompat

Description 描述


I want to build todolist app.I want to store information using RoomDatabse. 我想构建todolist app.I想要使用RoomDatabse存储信息。 I build Database with room and get infomation than save to database. 我建立数据库与房间和获取信息,而不是保存到数据库。 But when i click add button then i got exception. 但是当我点击添加按钮然后我得到了例外。 I have searched for an appropriate solution over the web but didn't find anything useful. 我已经在网上搜索了一个合适的解决方案,但没有找到任何有用的解决方案。 Please help me. 请帮我。

My exception 我的例外

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

My Android Studio Configuration 我的Android Studio配置

compileSdkVersion 27
buildToolsVersion '28.0.3'
minSdkVersion 15
targetSdkVersion 27

My Database Class 我的数据库类

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

@TypeConverters(DateConverter.class) public abstract class AppDatabase extends RoomDatabase { @TypeConverters(DateConverter.class)公共抽象类AppDatabase扩展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();

} }

My AddTaskActivity Code 我的AddTaskActivity代码

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);
    }
}

} }

In your gradle dependencies, do you use this? 在你的gradle依赖项中,你使用它吗?

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

If so, replace it with: 如果是这样,请将其替换为:

    implementation 'android.arch.persistence.room:runtime:1.1.1'
    annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'

you might be missing the dependency ... 你可能会错过依赖...

 androidx.core:core:1.0.0

which provides androidx.core.app.ActivityManagerCompat . 它提供了androidx.core.app.ActivityManagerCompat

Try migrating the project to AndroidX according to steps given in the link " https://developer.android.com/jetpack/androidx/migrate " 尝试按照“ https://developer.android.com/jetpack/androidx/migrate ”链接中的步骤将项目迁移到AndroidX

Change existing package and class names to those given in the sub-section " https://developer.android.com/jetpack/androidx/migrate#artifact_mappings " 将现有的包和类名更改为“ https://developer.android.com/jetpack/androidx/migrate#artifact_mappings ”子节中给出的名称和类名称

暂无
暂无

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

相关问题 java.lang.NoClassDefFoundError:解析失败:Landroidx/core/view/MenuHost; - java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/view/MenuHost; java.lang.NoClassDefFoundError:解析失败:Landroidx/appcompat/app/AppCompatActivity; - java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/app/AppCompatActivity; Android Espresso:java.lang.NoClassDefFoundError:解析失败:Landroidx/test/platform/io/FileTestStorage; - Android Espresso: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/platform/io/FileTestStorage; java.lang.NoClassDefFoundError:解析失败 - java.lang.NoClassDefFoundError: Failed resolution java.lang.NoClassDefFoundError:无法解决以下问题:Ljava / lang / invoke / MethodType; - java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/invoke/MethodType; Android ButterKnife java.lang.NoClassDefFoundError:无法解决以下问题:Lbutterknife / ButterKnife - Android ButterKnife java.lang.NoClassDefFoundError: Failed resolution of: Lbutterknife/ButterKnife java.lang.NoClassDefFoundError:解析失败:Lretrofit2/Retrofit$Builder; - java.lang.NoClassDefFoundError: Failed resolution of: Lretrofit2/Retrofit$Builder; java.lang.NoClassDefFoundError:解析失败:Landroid/webkit/PacProcessor - java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/PacProcessor java.lang.NoClassDefFoundError:解析失败:Lcom/google/gson/Gson; - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/gson/Gson; java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / android / gms / common / internal / zzbq附近的地方应用 - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq Nearby Place App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM