Issue
I am a newbie in android developement. I am just making a simple project to save the font size of the text entered everytime seekbar moves.
I completed the project with no errors but when I run the application it shows error message in Emulator says "Unfortunately SharedPreferences has been Stopped".
I have searched in below links as well for this and applied all but there was no such error in my case:
- Unfortunately app has stopped in Android Emulator
- Unfortunately HelloListView has stopped
- Unfortunately, *name of app* has stopped
- Unfortunately, MyApp has Stopped In Emulator
- unfortunately app has stopped in emulator
- unfortunately the application has stoped
- Unfortunately Project_Name Has Stopped
- "Unfortunately, app name has stopped." android device or emulator
and few more.
Here's project's LAYOUT file is (sharedprefer.xml):
<Seekbar android:id="@+id/sb"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditText android:id="@+id/et"
android:hint="@string/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/s" />
.Java file is (Main.java) :
import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.Toast;
public class Main extends Activity {
private SharedPreferences pref;
private String pName = "MyPref";
private EditText et;
private SeekBar sb;
private Button b;
private static final String FONT_SIZE_KEY = "fontsize";
private final static String TEXT_VALUE_KEY = "textvalue";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sharedprefer);
et = (EditText) findViewById(R.id.et);
sb = (SeekBar) findViewById(R.id.sb);
b = (Button) findViewById(R.id.b);
b.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
pref = getSharedPreferences(pName, MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
editor.putFloat(FONT_SIZE_KEY, et.getTextSize());
editor.putString(TEXT_VALUE_KEY, et.getText().toString());
editor.commit();
Toast.makeText(getBaseContext(), "Saved" , Toast.LENGTH_LONG).show();
}
});
pref = getSharedPreferences(pName, MODE_PRIVATE);
float fontsize = pref.getFloat(FONT_SIZE_KEY, 14);
sb.setProgress((int)fontsize);
et.setText(pref.getString(TEXT_VALUE_KEY, ""));
et.setTextSize(sb.getProgress());
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar sbar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
et.setTextSize(progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and I found errors in LOGCAT are :
07-17 13:12:18.369: I/Process(576): Sending signal. PID: 576 SIG: 9
07-17 13:12:30.760: D/AndroidRuntime(622): Shutting down VM
07-17 13:12:30.760: W/dalvikvm(622): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
07-17 13:12:30.810: E/AndroidRuntime(622): FATAL EXCEPTION: main
07-17 13:12:30.810: E/AndroidRuntime(622): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nsa.sharedpreferences/com.nsa.sharedpreferences.Main}: android.view.InflateException: Binary XML file line #7: Error inflating class Seekbar
07-17 13:12:30.810: E/AndroidRuntime(622): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.app.ActivityThread.access$600(ActivityThread.java:122)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.os.Looper.loop(Looper.java:137)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.app.ActivityThread.main(ActivityThread.java:4340)
07-17 13:12:30.810: E/AndroidRuntime(622): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 13:12:30.810: E/AndroidRuntime(622): at java.lang.reflect.Method.invoke(Method.java:511)
07-17 13:12:30.810: E/AndroidRuntime(622): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-17 13:12:30.810: E/AndroidRuntime(622): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-17 13:12:30.810: E/AndroidRuntime(622): at dalvik.system.NativeStart.main(Native Method)
07-17 13:12:30.810: E/AndroidRuntime(622): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class Seekbar
07-17 13:12:30.810: E/AndroidRuntime(622): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-17 13:12:30.810: E/AndroidRuntime(622): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.app.Activity.setContentView(Activity.java:1835)
07-17 13:12:30.810: E/AndroidRuntime(622): at com.nsa.sharedpreferences.Main.onCreate(Main.java:29)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.app.Activity.performCreate(Activity.java:4465)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
07-17 13:12:30.810: E/AndroidRuntime(622): ... 11 more
07-17 13:12:30.810: E/AndroidRuntime(622): Caused by: java.lang.ClassNotFoundException: android.view.Seekbar
07-17 13:12:30.810: E/AndroidRuntime(622): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-17 13:12:30.810: E/AndroidRuntime(622): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-17 13:12:30.810: E/AndroidRuntime(622): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:636)
07-17 13:12:30.810: E/AndroidRuntime(622): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
07-17 13:12:30.810: E/AndroidRuntime(622): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
07-17 13:12:30.810: E/AndroidRuntime(622): ... 21 more
Please tell me what can be its solution.
Solution
Change
<Seekbar android:id="@+id/sb"
with
<SeekBar android:id="@+id/sb"
the b
has to be a capital B
Answered By - Blackbelt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.