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 Testing in Android Unit Testing Viewing the Presenter

What am i doing wrong?

i can't tell what is wrong with my code. its telling me i have an error on line 11 and 24

MainActivity.java
public class MainActivity extends AppCompatActivity {
    TextView counter;
    Button button;
    MainActivityPresenter presenter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        presenter = new MainActivityPresenter(this);

        counter = (TextView) findViewById(R.id.textView);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              presenter.counterButtonClicked();

            }
        });
    }

              @Override
              public void increaseCounterByOne() {
                int count = Integer.parseInt(counter.getText().toString());
                counter.setText(Integer.toString(count + 1));

    }
}
MainActivityView.java
public interface MainActivityView {
  public void increaseCounterByOne();
}
MainActivityPresenter.java
public class MainActivityPresenter {
  MainActivityView view;

  public MainActivityPresenter(MainActivityView view) {
    this.view = view;
  }


  public void counterButtonClicked() {
    view.increaseCounterByOne();
  }
}

1 Answer

Carl Prude III
PLUS
Carl Prude III
Courses Plus Student 461 Points

I am struggling with the same issue. if i find a solution before anyone else I will share here but hope someone can provide a tip or answer

Thank you Carl