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
adam carignan
979 PointsDid I miss something or is a line missing?
This is from the android track in the shake detector section. it says to make the value for aString a true sentence by changing unknown to before or after but I don't see a 'otherString' variable here.
package com.example;
import android.os.Bundle;
import android.view.View;
import android.hardware.Sensor;
import android.hardware.SensorManager;
public class MainActivity extends Activity {
public static String aString;
private SensorManager mSensorManager;
private Sensor mAccelerometer;
private ShakeDetector mShakeDetector;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
aString = "This variable is set AFTER the 'otherString' variable in Activity";
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mShakeDetector = new ShakeDetector();
}
public void onPause() {
}
public void onResume() {
mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
}
}
4 Answers
Ernest Grzybowski
Treehouse Project ReviewerFor Challenge 2 of 5 they simply just want you to change the text UNKNOWN to BEFORE or AFTER. After you do this the challenge will complete. They tell you in the question that:
The otherString variable mentioned in the sentence is declared and set in the onCreate() method of the parent class of this MainActivity.
adam carignan
979 Pointsuhuh,,,so by "otherString" do they mean "another string" because I don't see anything outside of that phrase in quotations that says String otherString = someValue; or any string delcared other than the "aString" so am I just missing a fundamental piece here? I don't get it, and I'm long past it, but if its intrinsic to the coding I would love to have a better understanding
Ernest Grzybowski
Treehouse Project ReviewerIt is a bit confusing. I'm not sure I understand it, but then again I haven't watched those videos or done those challenges recently. Maybe Ben Jakuben can explain a bit better? In any case, it tells you that the variable mentioned is declared in the parent class, which would mean that you don't see it. Take a look at these docs: http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#d5e9946
adam carignan
979 PointsAh, magic. Got it. I'm sure this type of inner-working goo will be absorbed in context in future tutorials. Thank you Ernest
Ben Jakuben
Treehouse TeacherI just tried revamping this question, but it looks like I'm still missing something to make it clear. I'll try again. :-) But the idea I'm trying to convey is that variables from parent classes can be accessed and manipulated in subclasses (unless they are private).
adam carignan
979 PointsThank you Ben, I've thoroughly enjoyed your course. I will admit that when I re-took the challenge I just went with the other side of the coin, posted the forum inquiry, and moved on so I never saw the revision. Thank you for your clarification here; it makes more sense. It is awesome that these are "living" lessons with teachers that will help, totally worth the price of admission. I'm now onto the java script section of the track so i'll be out of your hair for a while :) thanks again, I look forward to your tutorials in the future.