访问 Sharedpreference 抛出 android.res.content.Resources$NotFoundException

Accessing Sharedpreference throws android.res.content.Resources$NotFoundException

我在项目中有 2 个活动,即 Main_ActivitySettings_Activity.

尝试从 android 工作室添加新的 SettinsActivity,但 删除了 它并添加了一个 空白activity 并命名为 Settings_ActivitySettings_Activity

OnCreate()中有如下代码
 sharedpreferences = getSharedPreferences("MyPref",Context.MODE_PRIVATE);

    try {
        pollTime = sharedpreferences.getInt("pollTime", 16);
        logClearCount = sharedpreferences.getInt("logClearCount", 6);
        eTPollTime.setText(pollTime);
        eTLogClearCount.setText(logClearCount);
        sharedpreferences.getBoolean("errorAlarm", false);
        cbErrorAlarm.setChecked(errAlarm);
    }
    catch (Exception ex) {
        Toast.makeText(getApplicationContext(),ex.toString(), Toast.LENGTH_LONG).show();
        tvDescription.setText(ex.toString());
    }

这里我抓到一个android.res.content.Resources$NotFoundException

eTPollTime.setText(pollTime);
eTLogClearCount.setText(logClearCount);

这将使系统在您的 xml 资源文件中查找资源 ID 值为 pollTime 或 logClearCount (int) 的资源。此资源将不存在,您会遇到异常。