我正在为Android开发一个应用程序,我不知道我所犯的错误或错误。我正在搜索超过4个小时的错误。
在使用SharedPreferences时,我得到了以下异常:
E/AndroidRuntime: FATAL EXCEPTION: main
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:23
我从片段中将一些数据保存到SharedPreference中,并希望在其他片段中使用这些数据。但是,我只希望在成功保存SharedPreferences的情况下执行片段事务,否则其他片段将无法检索数据(因为使用这些SharedPreference值来检索数据)。
我的代码:
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
... ... ... ... ... ... ... ... ...
public v
我已经设置了共享首选项,以便在应用程序中单击保存数据按钮后存储ArrayList的值。这部分运行得很好。
我遇到的问题是我有一个回收器视图适配器,它用行填充回收器视图。每行都包含一个复选框,选中该复选框后,该行中的文本将变为绿色,表示已完成。
我的问题是,如何将复选框状态添加到我的共享首选项中,并保存该状态,以便当我重新打开应用程序时,复选框被保存。
在主活动中的oncreate中的保存按钮
//Functionality for save button
final Button saveButton =findViewById(R.id.saveButtonGame);
正如标题所说,我想保存和检索某些字符串。但是我的代码不会通过检索或存储中的第一行。我试着点击这个链接:
private void savepath(String pathtilsave, int i) {
String tal = null;
// doesn't go past the line below
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
tal = String.valueOf(i);
editor.putString(tal, pa
然后显示或检索共享首选项对象中的数据。
下面是我的onCreate方法的样子:
public class ShoulderActivity extends Activity implements OnItemSelectedListener {
// The attribute used to store the value of the special test id <= used in sharedPreferences
int selectedPosition;
// T
我正在为android编写一个应用程序,在使用应用程序计费时,我很难用SharedPreferences保存int变量。我想在我的int变量中添加50分,然后用SharedPreferences保存它。当购买完成后,用户什么也没有得到,但它说支付Succesfull.How,我应该添加和保存50分吗?
这是我的代码:
private static final String HINT = "Hint";
private static final String VALUE = "VALUE";
int hints;
private static final Str
我有一个ExpandableListView,其中用户选择属于不同类别的不同项目。他的选择存储在ArrayList<Selected_Group>中。这是Selected_Group对象的代码:
public class Selected_Group extends Group {
private int selected_group_id;
private int trip_id;
private int group_id;
private ArrayList<Selected_Item> arr_selected_items;
private int marked
这是我的preference.xml代码
<EditTextPreference
android:defaultValue="3"
android:key="number"
android:numeric="integer"
android:summary="Enter how many Days older files"
android:title="Set Days" />
当我试图通过股票偏好来获得它的价值时,如下所示
这是我的储蓄程序代码,它将把分数、日期和球员名称保存到主板上:
mLeaderboardlist = new ArrayList<>();
Leaderboardmodel s = new Leaderboardmodel();
s.setDate("07/24/17");
s.setName(player.getText().toString());
s.setScore(Integer.parseInt(String.valueOf(yourScore.getText())));
请帮助和详细解释我如何修改我的代码。我是Flutter的初学者,现在我正在做任务,其本质是使用登录屏幕中的共享首选项并将用户数据保存在FireBase中。当用户第一次输入数据时,他进入了Home屏幕,但当用户退出应用程序并尝试再次登录时,他应该不需要输入密码并再次登录。 Also, I knocked out such an error import 'package:flutter/material.dart';
import 'package:logining/home_screen/home_screen.dart';
import 'p