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
pbaezogrfl
145 PointsTrying to open multiple activities
package com.brickbit.rene.jobipartknows;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import static android.R.attr.button;
import static com.brickbit.rene.jobipartknows.R.id.jpartPoemsButton;
public class MainActivity extends AppCompatActivity {
private Button mStartButton;
private Button mStartPoemsButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mStartButton = (Button)findViewById(R.id.clockButton);
mStartPoemsButton = (Button)findViewById(jpartPoemsButton);
}
mStartPoemsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick() {
startStory();
}
});
private void startStory() {
Intent poems = new Intent(this, jobipartpoems.class);
startActivity(poems);
}
mStartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick() {
startStory();
}
});
private void startStory() {
Intent intent = new Intent(this, clockactivity.class);
startActivity(intent);
}
}
2 Answers
markmneimneh
14,133 PointsHi
Looks like you have too many ) here
mStartPoemsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick() { startStory();
}
}); <<<<<<<<<<<<<<<<<<<<<<
Should be mStartPoemsButton.setOnClickListener(new View.OnClickListener()) { @Override public void onClick() { startStory();
}
}
and here
mStartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick() {
startStory();
}
});<<<<<<<<<<<<<<<<<<<<<<<<<<
should be
mStartButton.setOnClickListener(new View.OnClickListener()) {
@Override
public void onClick() {
startStory();
}
}
If this answers you your question, please mark question as answered.
Thanks
pbaezogrfl
145 PointsERRORS:
Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug] Information:0 errors Information:0 warnings Information:See complete output in console /Users/Rene/AndroidStudioProjects/JobipartKnows2/app/src/main/java/com/brickbit/rene/jobipartknows/MainActivity.java Error:(26, 41) error: <identifier> expected Error:(26, 42) error: illegal start of type Error:(26, 45) error: ')' expected Error:(26, 50) error: ';' expected Error:(26, 51) error: invalid method declaration; return type required Error:(28, 28) error: ';' expected Error:(32, 6) error: illegal start of type Error:(38, 36) error: <identifier> expected Error:(38, 37) error: illegal start of type Error:(38, 40) error: ')' expected Error:(38, 45) error: ';' expected Error:(38, 46) error: invalid method declaration; return type required Error:(40, 28) error: ';' expected Error:(44, 6) error: illegal start of type Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details. Information:BUILD FAILED Information:Total time: 25.095 secs