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 Build a Blog Reader Android App Adapting Data for Display in a List Handling Errors Using Dialogs

Axel McCode
Axel McCode
13,869 Points

[Solved]Handling Errors Using Dialogs Challenge Task 3 of 4 Help

I am stuck on this code challenge, I keep getting the same error in the editor and I do not know why, I have used the same code in my app project and it works perfectly.

Here is the error I get

JavaTester.java:85: error: method setTitle in class Builder cannot be applied to given types;
builder.setTitle(R.string.dialog_title);
       ^
  required: String
  found: int
  reason: actual argument int cannot be converted to String by method invocation conversion
JavaTester.java:86: error: method setMessage in class Builder cannot be applied to given types;
builder.setMessage(R.string.dialog_message);
       ^
  required: String
  found: int
  reason: actual argument int cannot be converted to String by method invocation conversion
2 errors
CodeChallenge.java
AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle(R.string.dialog_title);
builder.setMessage(R.string.dialog_message);
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="dialog_title">error</string>
  <string name="dialog_message">error</string>
</resources>
Axel McCode
Axel McCode
13,869 Points

Found the problem with my code :) I had to use getString() to get the string resource, like so:

builder.setTitle(getString(R.string.dialog_title));
builder.setMessage(getString(R.string.dialog_message));