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

Sean Gallagher
2,054 PointsTrouble with ImageButtons & new Intent: Can't resolve symbol
Was trying to recreate the lesson on my own from "Adding a Second Activity" from the Android Story App class. Both my attempts at creating either a regular button or Image Button with a new Intent gives me an error when it "Can't resolve symbol 'intent' ". I tried looking at the documentation but I'm a little too new to grasp what's written.
Can someone code review what I have? Is it an inheritance thing? Also had a similar issue with the name parameter in the Toast call.
<code> import android.app.Activity; import android.media.Image; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ImageButton; import android.widget.Toast;
import com.seattleshinebox.dinodictionary.R;
public class elementsSelectMainActivity extends Activity {
private ImageButton mWaterButton;
private ImageButton mAirButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_elements_select_main);
mWaterButton = (ImageButton)findViewById(R.id.waterElementButton);
mAirButton = (ImageButton)findViewById(R.id.airElementButton);
mWaterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// On Click show Toast message and make method call to start new activity
//Toast.makeText(elementsSelectMainActivity.this, name, Toast.LENGTH_LONG).show();
startTimePeriodSelection();
}
});
mAirButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(elementsSelectMainActivity.this, name, Toast.LENGTH_LONG).show();
}
});
}
private void startTimePeriodSelection() {
//Start new activity called timeperiodSelectActivity
Intent intent = new Intent(this, timeperiodSelectActivity.class);
startActivity(intent);
}
} </code>

Sean Gallagher
2,054 PointsAnother question, is there a more inclusive library I could add to capture most of what I would consider basic functionality rather than adding each and every library? Or maybe use a wildcard like android.content.* ? And is there a way I could just add this to the MainActivity and have the other activities inherent those libraries so I don't need to remember to import these to all activities?

miguelcastro2
Courses Plus Student 6,573 PointsYou can use wildcards like you mentioned, but it will import libraries that you don't need and it would be inefficient and would also waste application resources loading all of those unnecessary libraries. Inheritance does not to my knowledge work for import statements.
If you are using Android Studio and you reference a class that requires an import statement, you can easily move your cursor to the class declaration, hit ALT+ENTER (Command+ENTER on MAC) and it will automatically import the class. It makes it super easy to add your imports. One of the earlier videos about Android Studio explained this functionality.
Glad I could help.
1 Answer

Sean Gallagher
2,054 PointsThat was it - thanks so much! Adding "import android.content.Intent;" to the top was what I needed so I no longer got the "Cannot Resolve Symbol" error.
Unfortunately, I went back to the video and that wasn't mentioned. That should probably be added. I assumed that Intent was already part of another android library which was why I didn't think of it. I had the same problem with Button and ImageButton too.
miguelcastro2
Courses Plus Student 6,573 Pointsmiguelcastro2
Courses Plus Student 6,573 PointsYou need to make sure that the Intent library has been imported. I don't see it in your import statements. You can easily import required libraries in Android Studio by clicking on the red exclamation in the gutter or pressing ALT+ENTER over an error. You need to import this:
import android.content.Intent;
Also, for Toast the first parameter is the application context:
Toast.makeText(getApplicationContext(), "Some Message", Toast.LENGTH_LONG).show();