Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all :)

I have this exception when I try to lunch log in activity in android

01-12 21:04:28.994: E/AndroidRuntime(1442): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.msagroup.sbhmg/com.msagroup.sbhmg.LogIn}: java.lang.NullPointerException

here is my .XML file:

XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


    <EditText
        android:id="@+id/etmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="41dp"
        android:inputType="textEmailAddress"
        android:text="@string/email" >

        <requestFocus />
    </EditText>


    <EditText
        android:id="@+id/etpassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/etmail"
        android:layout_marginTop="16dp"
        android:inputType="textPassword" 
        android:text="@string/password"/>


    <Button
        android:id="@+id/btnlogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/etpassword"
        android:layout_marginTop="16dp"
        android:text="@string/login" />


    <TextView
        android:id="@+id/tvcomment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="@string/empty" />

</RelativeLayout>



and .Java file:

Java
package com.msagroup.sbhmg;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LogIn extends Activity {
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        
        Button _gotousermain = (Button) findViewById(R.id.btngotoenglishmain);
        EditText _etmail = (EditText) findViewById(R.id.etmail);
        EditText _etpassword = (EditText) findViewById(R.id.etmail);
        final String _email = _etmail.getText().toString();
        final String _pass = _etpassword.getText().toString();
        final TextView _tvcomm = (TextView) findViewById(R.id.tvcomment);
        
        _gotousermain.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				if(_email == "msay@live.com" && _pass == "123")
				{
					startActivity(new Intent(LogIn.this, ArMain.class));
				}
				else
				{
					if(_email == "msay@live.com" && _pass == "123")
					{
						startActivity(new Intent(LogIn.this, ArMain.class));
					}
					else
					{
						_tvcomm.setText("Invalid Info. !");
					}
				}
			}
		});
	}
}



thank you all :)
Posted
Updated 30-Mar-19 1:39am
Comments
[no name] 13-Jan-12 6:23am    
about the second condition, I change the value to "msay2@live.comm" and password to "1212", but still have the same problem< the app closed before run this activity

1 solution

I found the problem

it was a stupid one :\

the ID "btngotoenglishmain"

at

Button _gotousermain = (Button) findViewById(R.id.btngotoenglishmain);

is not exists at the xml file

thank you all :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900