-1

ユーザーがログインするときにユーザー名を乾杯したいのですが、ログインボタンをクリックしようとすると、強制的に閉じられました。を確認しますlogcatが、何も表示されません。

このコーディングは言っています。ログイン画面に入力した名前に応じて、ユーザー名をトーストします。パスワードはありません。

私のコードの何が問題なのかわかりません。誰かが私を助けることができますか?

ホームアクティビティ.java:

public class homeActivity extends Activity{
    Button btnLogIn;
    Button btnAbout;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.homescreen);
         // create a instance of SQLite Database

      // Get The Reference Of Buttons
         btnLogIn=(Button)findViewById(R.id.buttonLogIn);

         btnAbout=(Button)findViewById(R.id.buttonAbout);

         // Set OnClick Listener on SignUp button

            // set OnClick Listener on About button
            btnAbout.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    /// Create Intent for About  and start activity
                    Intent intentAbout=new Intent(getApplicationContext(),about.class);
                    startActivity(intentAbout);
                    }
                });


        }
    // Methods to handleClick Event of Sign In Button
        public void LogIn(View V)
           {
                final Dialog dialog = new Dialog(homeActivity.this);
                dialog.setContentView(R.layout.login);
                dialog.setTitle("Login");

                // get the Refferences of views
                final  EditText editTextUserName=(EditText)dialog.findViewById(R.id.editTextUserNameToLogin);

                Button btnLogIn=(Button)dialog.findViewById(R.id.buttonLogIn);

                // Set On ClickListener
                btnLogIn.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                        // get The User name and Password
                        String userName=editTextUserName.getText().toString();

                        // fetch the Password form database for respective user name
                // check if the Stored password matches with  Password entered by user
                        if(userName.equals(userName))
                        {
                            Toast.makeText(homeActivity.this, "Welcome," + userName, Toast.LENGTH_LONG).show();
                            dialog.dismiss();
                            Intent mainact=new Intent(getApplicationContext(),MainActivity.class);
                            startActivity(mainact);


                        }
                        else
                        {
                            Toast.makeText(homeActivity.this, "No Such Username", Toast.LENGTH_LONG).show();
                        }
                    }
                });

                dialog.show();          

        }

        @Override
        protected void onDestroy() {
            super.onDestroy();
            // Close The Database
        }

    }

ホームスクリーン.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"

    android:gravity="center_vertical"
    >


    <Button
        android:id="@+id/buttonLogIn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         android:text="Login" 
         android:onClick="LogIn"/>

    <Button
        android:id="@+id/buttonAbout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="About" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/home" />

</LinearLayout>

login.xml:

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

    <EditText
        android:id="@+id/editTextUserNameToLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="User Name"
        android:ems="10" >
        <requestFocus />
    </EditText>


    <Button
        android:id="@+id/buttonLogin"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Log In" />
</LinearLayout>
4

4 に答える 4

3

使用する必要があります

Button btnLogIn=(Button)dialog.findViewById(R.id.buttonLogin);

それ以外の

Button btnLogIn=(Button)dialog.findViewById(R.id.buttonLogIn);

あなたのLogIn方法であなたのButtonlogin.xmlにidが含まれてbuttonLoginいないのでbuttonLogIn

于 2014-01-21T06:39:39.910 に答える
0

これを試して..

あなたのボタンIDはあなたのlogin.xmlものですbuttonLoginが、あなたの与えられたIDとしてbuttonLogIn

    final  EditText editTextUserName=(EditText)dialog.findViewById(R.id.editTextUserNameToLogin);

    Button btnLogIn=(Button)dialog.findViewById(R.id.buttonLogin);
于 2014-01-21T06:40:02.553 に答える
0

setContentView(R.layout.login);それ以外のsetContentView(R.layout.homescreen);

于 2014-01-21T06:58:40.907 に答える