Error calling screen by boot

Asked

Viewed 53 times

1

Error in the button, simply close the application in the emulator when press to open another Activity, already everyone came to try to solve and nothing, follow the Logcat and the classes ( the problem is in btnCadastro ) :

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

     Button btnCadastro,button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
        setContentView(R.layout.activity_main);

        button = findViewById(R.id.button);
        btnCadastro= findViewById(R.id.btnCadastro);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent it = new Intent(getApplicationContext(),OCadastro.class);
                startActivity(it);
            }
        });

        btnCadastro.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                    Intent it = new Intent(getApplicationContext(), OCadastro.class);
                    startActivity(it);

            }
        });
    }
}

//////////////////

05-17 14:17:58.695 17020-17020/a.senai.login_campsell3 E/Androidruntime: FATAL EXCEPTION: main Process: a.senai.login_campsell3, PID: 17020 java.lang.Runtimeexception: Unable to start Activity ComponentInfo{a.senai.login_campsell3/a.senai.login_campsell3.OCadastro}: java.lang.Nullpointerexception: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$Onclicklistener)' on a null Object Reference at android.app.Activitythread.performLaunchActivity(Activitythread.java:2665) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2726) at android.app.Activitythread. -wrap12(Activitythread.java) at android.app.Activitythread$H.handleMessage(Activitythread.java:1477) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.Activitythread.main(Activitythread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:886) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:776) Caused by: java.lang.Nullpointerexception: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$Onclicklistener)' on a null Object Reference at a.senai.login_campsell3.OCadastro.onCreate(Ocadastro.java:25) at android.app.Activity.performCreate(Activity.java:6679) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.Activitythread.performLaunchActivity(Activitythread.java:2618) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2726)  at android.app.Activitythread. -wrap12(Activitythread.java)  at android.app.Activitythread$H.handleMessage(Activitythread.java:1477)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.Activitythread.main(Activitythread.java:6119)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:886)  at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:776)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.