Hi, I don't know what you did nor did I see the video, but try to do the 
following things:

first, give an id to your button, let us call it *calender_button*.

The in the below example do it like this:



public class MainActivity extends AppCompatActivity {


       Button calender; *(<--- this is step 1)*


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



     //set the button, like *(<--- this is step 2)*


     calender*= ** (Button) findViewById(R.id.**calender_button**);*


     calender*.setOnClickListener(this); **(<--- this is step 3)*

     
    }

    public void onClick(View v) *(<--- step 4; I am using the case/scenario 
here so as to allow you to add more buttons later on; it will also work with 
just one button)*
    {
        if(v.getId())
        {
            case R.id.*calender_button*:
                startActivity(new Intent(MainActivity.this, 
*yourNextActivity*.class));
            break;
        }
    }
}



Try this and let me know how it went 



Τη Παρασκευή, 29 Ιανουαρίου 2016 - 9:07:38 μ.μ. UTC+2, ο χρήστης Michael 
Maus έγραψε:
>
> I am just starting to learn Android Studio and am in now way a programmer.
>
> I have been following this tutorial to create a button to go to a new 
> activity, but get an error when the button is pressed and the app crashed.
>
> *Tutorial I followed:*
> https://www.youtube.com/watch?v=-xljI2_TRZg
>
> *Error I see in Android Monitor log:*
> 01-29 14:05:23.867 2225-2225/com.xplore_scuba.xplorescuba I/art: Not 
> late-enabling 
> -Xcheck:jni (already on)
> 01-29 14:05:23.950 2225-2225/com.xplore_scuba.xplorescuba W/System: 
> ClassLoader referenced unknown path: 
> /data/app/com.xplore_scuba.xplorescuba-2/lib/x86
> 01-29 14:05:24.124 2225-2243/com.xplore_scuba.xplorescuba 
> D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
> 01-29 14:05:24.174 2225-2243/com.xplore_scuba.xplorescuba 
> I/OpenGLRenderer: Initialized EGL, version 1.4
> 01-29 14:05:24.264 2225-2243/com.xplore_scuba.xplorescuba W/EGL_emulation: 
> eglSurfaceAttrib not implemented
> 01-29 14:05:24.264 2225-2243/com.xplore_scuba.xplorescuba 
> W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad7dfd60, 
> error=EGL_SUCCESS
> 01-29 14:05:30.529 2225-2225/com.xplore_scuba.xplorescuba 
> D/AndroidRuntime: Shutting down VM
> 01-29 14:05:30.530 2225-2225/com.xplore_scuba.xplorescuba 
> E/AndroidRuntime: FATAL EXCEPTION: main
>                                                                           
>   Process: com.xplore_scuba.xplorescuba, PID: 2225
>                                                                           
>   java.lang.IllegalStateException: Could not find method ButtonClick(View) 
> in a parent or ancestor Context for android:onClick attribute defined on 
> view class android.support.v7.widget.AppCompatImageButton with id 
> 'btn_calendar'
>                                                                           
>       at 
> android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:307)
>                                                                           
>       at 
> android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:266)
>                                                                           
>       at android.view.View.performClick(View.java:5198)
>                                                                           
>       at android.view.View$PerformClick.run(View.java:21147)
>                                                                           
>       at android.os.Handler.handleCallback(Handler.java:739)
>                                                                           
>       at android.os.Handler.dispatchMessage(Handler.java:95)
>                                                                           
>       at android.os.Looper.loop(Looper.java:148)
>                                                                           
>       at android.app.ActivityThread.main(ActivityThread.java:5417)
>                                                                           
>       at java.lang.reflect.Method.invoke(Native Method)
>                                                                           
>       at 
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
>                                                                           
>       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
> 01-29 14:05:33.364 2225-2228/com.xplore_scuba.xplorescuba W/art: 
> Suspending all threads took: 21.239ms
> 01-29 14:05:33.665 2225-2225/com.xplore_scuba.xplorescuba I/Process: 
> Sending signal. PID: 2225 SIG: 9
>
>
>
> I have my files on GitHub if anyone would like to dig into it.  Its a 
> small project right now with a single button and two activities.
> https://github.com/mouse51180/NewActivityTest
>
>
> I dont know why the OnClick is having an issue and dont know what or where 
> to look to correct this.  My suspicions are that something needs to be 
> changed or added to the MainActivity.java file.
>
> The button itself has the "onClick" parameter set to "onButtonClick".  Im 
> not sure is this might be were part of the problem is as well.
>
> *MainActivity.java file:*
>
> package com.xplore_scuba.xplorescuba;
>
> import android.content.Intent;
> import android.support.v7.app.AppCompatActivity;
> import android.os.Bundle;
> import android.view.Display;
> import android.view.View;
>
>
> public class MainActivity extends AppCompatActivity {
>
>     @Override
>     protected void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.activity_main);
>     }
>
>     public void onButtonClick(View v)
>     {
>         if(v.getId() == R.id.btn_calendar)
>         {
>             Intent i = new Intent(MainActivity.this, Display.class);
>             startActivity(i);
>         }
>     }
> }
>
>
>
> Thanks in advance for any guidance you can provide.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/485eac89-28af-4e6a-8868-cb99d75c5614%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to