Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (retired 2014) Shaking Things Up The Activity Lifecycle

Siddharth Saravanan
Siddharth Saravanan
1,208 Points

Override error. Please help!

I followed the videos instructions and I did everything the exact way the videos said to. I am getting an error at the "OnResume()" and the "OnPause()". The quick fix says to remove the "@Override" annotation but if I do that, when I run the app on my phone(Samsung Galaxy S III) I tried shaking it but nothing happened. I even tried shaking it in all directions possible. Please if anyone can help me please help!

Siddharth Saravanan
Siddharth Saravanan
1,208 Points

Ben Jakuben do you think you can help me with this problem?

5 Answers

Did you remember to type super.onPause(); and super.onResume()? Also did you actually camelcase both of the method names? Camelcase means capitalize the first letter for each word? You should not have capitalized the first letter in each method name. Only constants and class names should start with a capital letter. This is very important as the method name is case sensitive. The @Override annotation is a flag to the compiler to enforce that it does indeed match the original method's signature that you are overriding.

Siddharth Saravanan
Siddharth Saravanan
1,208 Points

Yes I did type "super.onPause();" and "super.onResume()". I think I have the code right, but im not sure. Ill put it below.

 @Override
   public void OnResume() {
// The first error is on the line above
       super.onResume();
       mSensorManager.registerListener(mShakeDetector, mAccelerometor  ,
               SensorManager.SENSOR_DELAY_UI);
   }
   @Override
   public void OnPause() {
// The second error is on the line above
       super.onPause();
       mSensorManager.unregisterListener(mShakeDetector);


// The quick fix says that the errors will go away if I remove the "@Override" annotation. 
// But if I do that the app wont do anything when I shake my phone

No remember. I asked you about the capitalization of your method names. You need to make the word 'On' lowercase like 'on'

Siddharth Saravanan
Siddharth Saravanan
1,208 Points

Yes they are in the main activity.java file and yes they are capitalized. Ohhhh I'm sorry i didn't realize that the OnPause and OnResume have to have uncapitalized "o"s not capital. I haven't tried on my computer yet but when I get to my computer .Thank you ALOT for helping me out. I'll get back to you if it worked out or not.

Are your methods inside of MainActivity.java?

Can we close this question? I think it has been answered because the original poster has acknowledged that the solution provided was able to fix his problem.