sharedPreferencesImpl.getInt ClassCastException Ошибка - PullRequest
0 голосов
/ 15 апреля 2020

Мое Android приложение работает на большинстве телефонов, но выдает такую ​​остановленную ошибку при открытии на некоторых телефонах (RedMi Note 8 и c.) Я использую sharedPreferences для хранения данных. но я не знаю, в чем причина ошибки. Можете ли вы помочь мне, пожалуйста?

@SuppressLint("InflateParams")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    } else {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    Intent intent = getIntent();
    locale = intent.getStringExtra("locale");

    localeMethod(locale);
    setContentView(R.layout.activity_main);

    instance = this;
    defaultlocale = Locale.getDefault().getLanguage().toUpperCase();
    Log.d("TAG_LOCALE", "LOCALE\t" + locale);
    Log.d("TAG_LOCALE", "DEFAULT\t" + defaultlocale);


    sharedPreferences = context.getSharedPreferences(MAIN_DATA, Context.MODE_PRIVATE);
    sucheck = sharedPreferences.getInt(SUCHECK, 0);
    bildirim = sharedPreferences.getBoolean(BILDIRIM, true);
    rateme = sharedPreferences.getBoolean(RATEME, true);
    cinsiyetdegisim = sharedPreferences.getString(CINSIYET_KEY, getString(R.string.erkek));
    kilogelen = sharedPreferences.getInt(KILO_KEY, 86);
    boygelen = sharedPreferences.getInt(BOY_KEY, 186);
    boyuncgelen = sharedPreferences.getInt(BOYUN_CEV, 36);
    belcgelen = sharedPreferences.getInt(BEL_CEV, 80);
    kalcacgelen = sharedPreferences.getInt(KALCA_CEV, 90);
    yas = sharedPreferences.getInt(YAS_KEY, 21);
    getHAREKET = sharedPreferences.getInt(HAREKET, 0);
    getISTEK = sharedPreferences.getInt(ISTEK, 0);
    gelenMacro = sharedPreferences.getInt(MACRO_KEY, 0);
    gelenFormul = sharedPreferences.getInt(FORMUL_KEY, 0);
    blink_settings = sharedPreferences.getBoolean(BLINK_SETTINGS, true);
    iconcheck = sharedPreferences.getInt(TRACKER_ICON, 0);
    trackercheck = sharedPreferences.getInt(TRACKER_CHECK, 0);
    saat = sharedPreferences.getInt(TRACKER_SAAT, 10);
    dk = sharedPreferences.getInt(TRACKER_DK, 30);
    getsagliklimin = sharedPreferences.getInt(SAGLIKLI_MIN, 0);
    getsagliklimax = sharedPreferences.getInt(SAGLIKLI_MAX, 0);


    sharedpreflistener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            sucheck = sharedPreferences.getInt(SUCHECK, 0);
            bildirim = sharedPreferences.getBoolean(BILDIRIM, true);
            cinsiyetdegisim = sharedPreferences.getString(CINSIYET_KEY, getString(R.string.erkek));
            kilogelen = sharedPreferences.getInt(KILO_KEY, 86);
            boygelen = sharedPreferences.getInt(BOY_KEY, 186);
            boyuncgelen = sharedPreferences.getInt(BOYUN_CEV, 36);
            belcgelen = sharedPreferences.getInt(BEL_CEV, 80);
            kalcacgelen = sharedPreferences.getInt(KALCA_CEV, 90);
            yas = sharedPreferences.getInt(YAS_KEY, 21);
            getHAREKET = sharedPreferences.getInt(HAREKET, 0);
            getISTEK = sharedPreferences.getInt(ISTEK, 0);
            gelenMacro = sharedPreferences.getInt(MACRO_KEY, 0);
            gelenFormul = sharedPreferences.getInt(FORMUL_KEY, 0);
            blink_settings = sharedPreferences.getBoolean(BLINK_SETTINGS, true);
            iconcheck = sharedPreferences.getInt(TRACKER_ICON, 0);
            trackercheck = sharedPreferences.getInt(TRACKER_CHECK, 0);
            saat = sharedPreferences.getInt(TRACKER_SAAT, 10);
            dk = sharedPreferences.getInt(TRACKER_DK, 30);
            rateme = sharedPreferences.getBoolean(RATEME, true);
            getsagliklimin = sharedPreferences.getInt(SAGLIKLI_MIN, 0);
            getsagliklimax = sharedPreferences.getInt(SAGLIKLI_MAX, 0);

        }
    };

`Это продолжается так. Я не понимаю, почему есть некоторые телефоны. Причина ошибки нигде не написана. Я также использую аварийные системы Firebase, и причина ошибки не написана

enter image description here

enter image description here

ИЗОБРАЖЕНИЕ 3

enter image description here

ИЗОБРАЖЕНИЕ 4

enter image description here

Манифест. xml

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:resizeableActivity="false"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="AllowBackup,GoogleAppIndexingWarning"
    tools:targetApi="n">
    <activity
        android:name=".SplashActivity"
        android:theme="@style/AppThemeWelcome"
        android:windowSoftInputMode="stateAlwaysHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".IntroductionActivity"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="stateAlwaysHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

SplashActivity. java

public class SplashActivity extends AppCompatActivity {

private SharedPreferences.OnSharedPreferenceChangeListener sharedpreflistener;
private SharedPreferences sharedPreferences;
private boolean getLAUNCH;
private String MAIN_DATA = "com.kmkappdeveloper.detaylivucutkitleindeksi.MAIN";
private String LAUNCH = "com.kmkappdeveloper.detaylivucutkitleindeksi.LAUNCH";
private String LOCALE_KEY = "com.kmkappdeveloper.detaylivucutkitleindeksi.LOCALE_KEY";
Context context=this;
String locale;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sharedPreferences = context.getSharedPreferences(MAIN_DATA, Context.MODE_PRIVATE);
    getLAUNCH = sharedPreferences.getBoolean(LAUNCH, false);
    locale = sharedPreferences.getString(LOCALE_KEY, "");
    sharedpreflistener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            getLAUNCH = sharedPreferences.getBoolean(LAUNCH, false);
            locale = sharedPreferences.getString(LOCALE_KEY, "");
        }
    };

    if (getLAUNCH) {
        mainActivity(locale);
    }else{
        introActivity();
    }

}


private void mainActivity(String setLocale) {
    Intent intent = new Intent(SplashActivity.this, MainActivity.class);
    intent.putExtra("locale",setLocale);
    startActivity(intent);
    finish();
}

private void introActivity() {
    startActivity(new Intent(SplashActivity.this, IntroductionActivity.class));
    finish();
}

}

...