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

Methods that we reference that should be from android aren't showing up? FindViewbyID etc...

All of the sudden in this interactive story project my find view by ID methods and things like onCreate just come up as Red and now I can't emulate when I do this is my logcat.

```C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:17: error: cannot find symbol public class StoryActivity extends ActionBarActivity { ^ symbol: class ActionBarActivity C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:27: error: method does not override or implement a method from a supertype @Override ^ C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:29: error: cannot find symbol super.onCreate(savedInstanceState); ^ symbol: variable super location: class StoryActivity C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:30: error: cannot find symbol setContentView(R.layout.activity_story); ^ symbol: method setContentView(int) location: class StoryActivity C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:31: error: cannot find symbol Intent intent = getIntent(); ^ symbol: method getIntent() location: class StoryActivity C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:32: error: cannot find symbol String name = intent.getStringExtra(getString(R.string.key_name)); ^ symbol: method getString(int) location: class StoryActivity C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:39: error: cannot find symbol mImageView = (ImageView)findViewById(R.id.storyImageView); ^ symbol: method findViewById(int) location: class StoryActivity C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:40: error: cannot find symbol mTextView = (TextView)findViewById(R.id.storyTextView); ^ symbol: method findViewById(int) location: class StoryActivity C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:41: error: cannot find symbol mChoice1 = (Button)findViewById(R.id.choiceButton1); ^ symbol: method findViewById(int) location: class StoryActivity C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:42: error: cannot find symbol mChoice2 = (Button)findViewById(R.id.choiceButton2); ^ symbol: method findViewById(int) location: class StoryActivity C:\Users\Andreas\AndroidStudioProjects\InteractiveStory\app\src\main\java\dredaydesigns\interactivestory\ui\StoryActivity.java:50: error: cannot find symbol Drawable drawable = getResources().getDrawable(mCurrentPage.getImageId()); ^ symbol: method getResources() location: class StoryActivity 11 errors

FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugJava'. > Compilation failed; see the compiler error output for details. ```

here is my code for the storyactivity.java

package dredaydesigns.interactivestory.ui;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import dredaydesigns.interactivestory.R;
import dredaydesigns.interactivestory.model.Page;
import dredaydesigns.interactivestory.model.Story;


public class StoryActivity  {

public final String TAG = StoryActivity.class.getSimpleName();
    private Story mStory = new Story();
    private ImageView mImageView;
    private TextView mTextView;
    private Button mChoice1;
    private Button mChoice2;
    private Page mCurrentPage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_story);
        Intent intent = getIntent();
        String name = intent.getStringExtra(getString(R.string.key_name));
        if (name == null) {
            name = "Friend";
        }

        Log.d(TAG,name);

        mImageView = (ImageView)findViewById(R.id.storyImageView);
        mTextView = (TextView)findViewById(R.id.storyTextView);
        mChoice1 = (Button)findViewById(R.id.choiceButton1);
        mChoice2 = (Button)findViewById(R.id.choiceButton2);

        loadPage(0);
    }



    private void loadPage(int choice){
       mCurrentPage = mStory.getPage(choice);

        Drawable drawable = getResources().getDrawable(mCurrentPage.getImageId());
                mImageView.setImageDrawable(drawable);

        mTextView.setText(mCurrentPage.getText());

        mChoice1.setText(mCurrentPage.getChoice1().getText());
        mChoice2.setText(mCurrentPage.getChoice2().getText());

        mChoice1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int nextPage = mCurrentPage.getChoice1().getNextPage();
                loadPage(nextPage);
            }
        });
        mChoice2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int nextPage = mCurrentPage.getChoice2().getNextPage();
                loadPage(nextPage);
            }
        });

    }

}

1 Answer

Where you start the class with:

public class StoryActivity  {

Your activity needs to extend one of Android's Activity classes to get access to those methods showing up in red. So change it to the following and use Alt+Enter to get the import statement.

public class StoryActivity extends Activity {

THANK YOU!