0

I would like to create a dialog, which will prompt the user to key in his/her name. It will capture the username for the first time hat it is used and display the username whenever the user login.

I've done the coding, But there's an error occurring. WHen I want to start the application, there is a force close error.

logcat:

01-25 01:03:24.023: E/AndroidRuntime(8242): FATAL EXCEPTION: main
01-25 01:03:24.023: E/AndroidRuntime(8242): android.app.SuperNotCalledException: Activity {com.example.fuellogproject/com.example.fuellogproject.homeActivity} did not call through to super.onCreate()
01-25 01:03:24.023: E/AndroidRuntime(8242):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2076)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at android.app.ActivityThread.access$700(ActivityThread.java:140)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at android.os.Looper.loop(Looper.java:137)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at android.app.ActivityThread.main(ActivityThread.java:4921)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-25 01:03:24.023: E/AndroidRuntime(8242):     at dalvik.system.NativeStart.main(Native Method)

homeactivity.java

public class homeActivity extends Activity{
    Button btnLogIn;
    Button btnAbout;
    SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        final SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(this);
        String userName = prefs.getString("user_name", null);
        if (userName == null) {
            EditText input = new EditText(this);
            input.setId(1000);         




            AlertDialog dialog = new AlertDialog.Builder(this)
                    .setView(input).setTitle("Enter your username!")
                    .setPositiveButton("Ok",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    EditText theInput = (EditText) ((AlertDialog) dialog)
                                            .findViewById(1000);
                                    String enteredText = theInput.getText()
                                            .toString();
                                    if (!enteredText.equals("")) {
                                        SharedPreferences.Editor editor = prefs
                                                .edit();
                                        editor.putString("user_name",
                                                enteredText);
                                        editor.commit();
                                    }
                                }
                            }).create();
            dialog.show();
        }
    }

}
2
  • is this answer worked?? Jan 24, 2014 at 17:43
  • I've yet to try because it can't work
    – Chloe
    Jan 25, 2014 at 3:19

1 Answer 1

0

U missed super.onCreate().. in onCreate() method....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.