Android app force closes while going on another activity

倾然丶 夕夏残阳落幕 提交于 2019-12-06 15:03:48

Change Your LoginActivity1 Activity as:

public class LoginActivity1 extends Activity {

    Button btnLinkToRegistrScrn;
    Button loginbtn1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     setContentView(R.layout.login);
     addListenerOnButton();
        // Link to Register Screen 
        btnLinkToRegistrScrn = (Button) findViewById(R.id.LinkToRegisterScreen); 
        btnLinkToRegistrScrn.setOnClickListener(new View.OnClickListener() { 
           @Override
            public void onClick(View v) { 
                Intent i = new Intent(v.getContext(), TrekEyesAndroidActivity.class); 
              //  i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);
                } 
       }); 
   }
    public void addListenerOnButton() {

        //final Context context2 = this;

            loginbtn1 = (Button) findViewById(R.id.btnLogin);

            loginbtn1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(arg0.getContext(), DashboardActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                         startActivity(intent);   
            }

        });
    }
   }

and in xml change TextView to Button as

<Button
         android:id="@+id/LinkToRegisterScreen"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="25dip"

            android:textColor="#21dbd4"
            android:textStyle="bold" 
            android:text="@string/noAccountRegisterME" />  

in Login.xml you declared

<TextView
    android:id="@+id/LinkToRegisterScreen"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

and while mapping LoginActivity1.java

 btnLinkToRegistrScrn = (Button) findViewById(R.id.LinkToRegisterScreen); 

so just change the TextView to Button

<Button
    android:id="@+id/LinkToRegisterScreen"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>
Niranj Patel

In your login.xml

<TextView
            android:id="@+id/LinkToRegisterScreen"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="25dip"

            android:textColor="#21dbd4"
            android:textStyle="bold" 
            android:text="@string/noAccountRegisterME" />

android:id="@+id/LinkToRegisterScreen" and it is EditText and you are doing btnLinkToLoginScrn = (Button) findViewById(R.id.LinkToLoginScreen); so it would be null pointer..

so just change Button instead of TextView in your login.xml

i think u should concentrate the braces.you give the code to add listeneraddListenerOnButton()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!