nullpointerexception on launcher? android

Stender

i'm trying to create a really simple login page, but I get an error when i try to launch the app. I don't get it at all, since that I've basically made it like I had the other launcher. And i have put the intent filter on this new activity. any help would be appreciated, since I have to Present it tomorrow at my exam. Here's the code. the thing about insert, is just for now, and I will change that later.

public class LoginActivity extends Activity implements OnClickListener {

EditText loginUsername,loginPassword;
Button loginButton;
SQLiteDatabase db;

public void onCreate(Bundle savedInstanceState)
{ 

    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    loginUsername=(EditText)findViewById(R.id.loginUsername);
    loginPassword=(EditText)findViewById(R.id.loginPassword);
    loginButton.setOnClickListener(this);
    db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
    db.execSQL("CREATE TABLE IF NOT EXISTS studentTest5(rollno VARCHAR,name VARCHAR,lastname VARCHAR,password VARCHAR,marks VARCHAR, phone VARCHAR, email VARCHAR);");
    db.execSQL("INSERT INTO studentTest5 VALUES('1','Lars','Hansen','1234','7','60158096','[email protected]');");
}


@Override
public void onClick(View view) {
    // TODO Auto-generated method stub
    if(view==loginButton)
    {
        if(loginUsername.getText().toString().trim().length()==0||
           loginPassword.getText().toString().trim().length()==0)
        {
            showMessage("Error", "Please enter all values");
            return;
        }
        Cursor c=db.rawQuery("SELECT * FROM studentTest5 WHERE name='"+loginUsername.getText()+"'", null);
        if(c.moveToFirst())
        {
            if(c.getString(3)==loginPassword.getText().toString())
            {
                showMessage("sucess", "user exists");
                //loginPassword.setText(c.getString(3));
                } else {
                    showMessage("Error", "incorrect password");
                }


        }
        else
        {
            showMessage("Error", "Invalid Rollno");
            clearText();
        }

    }

}
 public void showMessage(String title,String message)
    {
        Builder builder=new Builder(this);
        builder.setCancelable(true);
        builder.setTitle(title);
        builder.setMessage(message);
        builder.show();
    }
    public void clearText()
    {
        loginUsername.setText("");
        loginPassword.setText("");

    }

}

here is the xml

<TextView
    android:id="@+id/loginWelcome"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="65dp"
    android:text="Welcome!"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
    android:id="@+id/loginUsername"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/loginWelcome"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:ems="10"
    android:hint="Login"
    android:inputType="textPersonName" />

<EditText
    android:id="@+id/loginPassword"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/loginUsername"
    android:layout_alignRight="@+id/loginUsername"
    android:layout_below="@+id/loginUsername"
    android:layout_marginTop="14dp"
    android:ems="10"
    android:hint="Password"
    android:inputType="textPassword" />

<Button
    android:id="@+id/loginButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/loginPassword"
    android:layout_alignRight="@+id/loginPassword"
    android:layout_below="@+id/loginPassword"
    android:layout_marginTop="30dp"
    android:text="Login" />

</RelativeLayout>

and here's the error message

   FATAL EXCEPTION: main
   Process: com.technotalkative.viewstubdemo, PID:     10998
   java.lang.RuntimeException: Unable to start activity      ComponentInfo{com.technotalkative.viewstubdemo/com.technotalkative.viewstubdemo.LoginActivity}:      java.lang.NullPointerException
    at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
    at android.app.ActivityThread.access$800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.NullPointerException
    at com.technotalkative.viewstubdemo.LoginActivity.onCreate(LoginActivity.java:27)
    at android.app.Activity.performCreate(Activity.java:5231)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
    ... 11 more
Blackbelt
  loginButton.setOnClickListener(this);

you missed the findViewById (object's initialization) for loginButton

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Android Wear Launcher

分類Dev

Android App Launcher in ReactNative like Microsoft, Google Launcher

分類Dev

Android MediaRecorder NullPointerException

分類Dev

Android BottomSheetBehavior setState()NullPointerException

分類Dev

android MediaPlayer NullPointerException

分類Dev

Android ArrayAdapter NullPointerException getID

分類Dev

Android NullPointerException + GetDatabaseLocked

分類Dev

Android:findViewById NullpointerException

分類Dev

Android NullPointerException Error Message

分類Dev

Android onClickListener NullPointerException

分類Dev

android bindService()NullPointerException

分類Dev

android bindService()NullPointerException

分類Dev

NullPointerException onCreate()Android Studio

分類Dev

Android AIDL iBinder NullPointerException

分類Dev

NullPointerException Android getContext()

分類Dev

ImageSwitcher Android NullPointerException

分類Dev

Creating an application launcher icon for Android Studio

分類Dev

Android Appwidget not showing in launcher after installation

分類Dev

android.intent.category.LAUNCHERとandroid.intent.category.IOT_LAUNCHERの違い

分類Dev

Android-RecyclerViewのNullPointerException

分類Dev

NullPointerException with Sharing Intent in Android Nougat

分類Dev

Android-NullPointerException:storage == null

分類Dev

nullPointerExceptionヘルプ(android)

分類Dev

Androidの不明なNullPointerException

分類Dev

android webview CustomView onHideCustomView nullpointerexception

分類Dev

android webview CustomView onHideCustomView nullpointerexception

分類Dev

AndroidのDsClientManagerのNullPointerException

分類Dev

Android-RecyclerView NullPointerException getItemCount?

分類Dev

Android Launcher3-GoogleNowページ

Related 関連記事

  1. 1

    Android Wear Launcher

  2. 2

    Android App Launcher in ReactNative like Microsoft, Google Launcher

  3. 3

    Android MediaRecorder NullPointerException

  4. 4

    Android BottomSheetBehavior setState()NullPointerException

  5. 5

    android MediaPlayer NullPointerException

  6. 6

    Android ArrayAdapter NullPointerException getID

  7. 7

    Android NullPointerException + GetDatabaseLocked

  8. 8

    Android:findViewById NullpointerException

  9. 9

    Android NullPointerException Error Message

  10. 10

    Android onClickListener NullPointerException

  11. 11

    android bindService()NullPointerException

  12. 12

    android bindService()NullPointerException

  13. 13

    NullPointerException onCreate()Android Studio

  14. 14

    Android AIDL iBinder NullPointerException

  15. 15

    NullPointerException Android getContext()

  16. 16

    ImageSwitcher Android NullPointerException

  17. 17

    Creating an application launcher icon for Android Studio

  18. 18

    Android Appwidget not showing in launcher after installation

  19. 19

    android.intent.category.LAUNCHERとandroid.intent.category.IOT_LAUNCHERの違い

  20. 20

    Android-RecyclerViewのNullPointerException

  21. 21

    NullPointerException with Sharing Intent in Android Nougat

  22. 22

    Android-NullPointerException:storage == null

  23. 23

    nullPointerExceptionヘルプ(android)

  24. 24

    Androidの不明なNullPointerException

  25. 25

    android webview CustomView onHideCustomView nullpointerexception

  26. 26

    android webview CustomView onHideCustomView nullpointerexception

  27. 27

    AndroidのDsClientManagerのNullPointerException

  28. 28

    Android-RecyclerView NullPointerException getItemCount?

  29. 29

    Android Launcher3-GoogleNowページ

ホットタグ

アーカイブ