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 trialTravis LeBlanc
1,833 PointsAdding a Shake Detector.
So, I've gotten about as far as adding a shake detector to the Crystal Ball app, and I'm at the point where you initialize mShakeDetector, but when I select the OnShakeListener using Intellisense, I get an error for the entire onShake method it creates.
"The constructor ShakeDetector(new OnShakeListener(){}) is undefined."
It gives me two options: either changing the constructor, or creating a constructor, but both change the code in the ShakeDetector.java file.
8 Answers
Ben Jakuben
Treehouse TeacherAwesome! Glad you figured it out. Hopefully it's not long before you feel comfortable quitting your day job.
I'll post that other thread here for @Travis and anyone else running into this issue: http://teamtreehouse.com/forum/a-couple-of-issues-with-shaking-things-up
And the relevant notes:
As for the @Override problem, that usually occurs when project settings get set to an older version of Java. This can happen when importing a project into Eclipse, among other reasons.
Try the following solution and let us know if it works or not. In Eclipse, right-click on the Crystal Ball project in Package Explorer and select Properties at the bottom. Click on Java Compiler on the left side and then uncheck "Enable project specific settings" (if it is checked). Then click on the "Configure Workspace Settings" link in the upper-right and set "Compiler Compliance Level" to 1.6.
The @Override annotation was introduced in Java 1.6 (or Java 6 as it's often called).
Ben Jakuben
Treehouse TeacherHi @Travis,
It sounds like there is some sort of problem including the ShakeDetector.java file. Are you using the same "com.teamtreehouse.crystal.ball" package name as you see at the top of ShakeDetector.java?
Does your ShakeDetector.java file include this constructor at line 37?
// Constructor that sets the shake listener
public ShakeDetector(OnShakeListener shakeListener) {
mShakeListener = shakeListener;
}
And this interface definition at the bottom?
public interface OnShakeListener {
public void onShake();
}
Also, if you zip up your project and send it as an attachment to help@teamtreehouse.com then I can take a look and see if anything jumps out.
Rory Callendar
1,014 PointsI may be having similar troubles...
I'm all done with this lesson, but still have a red wavy line under "onShake" ...line 40. It states method onShake must override a superclass.
I also have similar must override messages within the ShakeDetector.java ...lines... 42 public void onSensorChanged(SensorEvent event) {
and
84 public void onAccuracyChanged(Sensor sensor, int accuracy) {
Any hints?
Ben Jakuben
Treehouse TeacherThis is a tough one to troubleshoot out of the context of the whole project. Rory, would you mind zipping up your files and also emailing them to help@teamtreehouse.com? I can take a look at the project and post any feedback in here in case anyone else runs into this problem. Thanks!
Braden Ripple
Courses Plus Student 5,631 Pointshey ben, I downloaded the code for the shake detector directly and when I imported into eclipse and run it on my HTC EVO shift, it didn't work. I know i have an accelerometer because I tested it with another app, but perhaps is there something with how I might have imported it? ~thanks in advance
Ben Jakuben
Treehouse TeacherInteresting. I wonder what is different? Can you try downloading the official Crystal Ball app from Google Play and see if it works on your EVO? If it does, then we'll have to look at the project code. If not, then we'll have to troubleshoot the ShakeDetector code and maybe try adjusting the parameters. Let me know how the Treehouse Crystal Ball works.
Braden Ripple
Courses Plus Student 5,631 PointsHey I just deleted the project files and re-imported them back in, strangely it worked this time, I almost certain it was something wrong with how I had Eclipse set up or something that I did, but it's working fine now :)
Rory Callendar
1,014 PointsWait! I figured it out by reading your conversation with Nicole...I should've done this before posting here. I did not have the same line error you found in Nicole's, but I decided to try removing the @Override Notations at lines 39 in MainActivity and 83 and 42 in ShakeDetector,
At this point, I did not have any read wavy lines...
then I toggled the settings in the Crystal Ball package as you instructed Nicole (unchecked Enable project specific settings)...because that sounded like a smart thing to do.
Everything works now!
Don't worry I won't quit my day job yet. Thank you!
Rodrigo Muñoz
Courses Plus Student 20,171 PointsI've tried this using the 1.5 , 1.6 and 1.7 compiler version but still can't fix the error
Ben Jakuben
Treehouse Teacher@Rodrigo, would you mind zipping up your project directory and sending it to help@teamtreehouse.com? I can take a look and see if anything jumps out.
Eric De Wildt
Courses Plus Student 13,077 PointsThe code is not working for me either. Anytime I get to "On(Something)Listener" the code gives me an error. For the Media player part of the project I just release the player during onStop(). But here I cant not figure out a workaround. In Googles developer reference files they said that the ShakeDetector Method was deprecated in version 3. i have tried creating this code on AIDE-IDE and AndroidStudio and it still doesn't work. I'm at a loss and really need some help.
Ben Jakuben
Treehouse TeacherHi Eric, would you mind pasting your code as a new question in the Forum? We'll get you straightened out!
Diego Mariano Casso
392 PointsDiego Mariano Casso
392 PointsI'm trying this solution but when I click "ok" a box pop's up telling me "the compiler settings changed a rebuild of the project is required, build this project now?" Now, the quick fix for those red lines I have is to delete @override, because it must be overriding a superclass method. Which one should I try??
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherI would make the compiler setting changes, clean and rebuild your project, and possibly even restart Eclipse and rebuild again. It seems sometimes a restart is required for certain changes.