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

what wrong with my code l am stuck guys package com.example; import java.util.Date;

package com.example;

import java.util.Date;

public class BlogPost { private String mAuthor; private String mTitle; private String mBody; private String mCategory; private Date mCreationDate;

public BlogPost(String author, String title, String body, String category, Date creationDate) {
  mAuthor = author;
  mTitle = title;
  mBody = body;
  mCategory = category;
  mCreationDate = creationDate;
}

@Override public String toString(){ return "BlogPost: \""+mTITLE + "\" -@" + mAUTHOR; } } public String getAuthor() { return mAuthor; }

public String getTitle() {
  return mTitle;
}

public String getBody() {
  return mBody;
}

public String getCategory() {
  return mCategory;
}

public Date getCreationDate() {
  return mCreationDate;

}

11 Answers

l saw a chain of errors

./com/example/BlogPost.java:2: error: class, interface, or enum expected import : import java.util*; ^

the errows

      ^
./com/example/BlogPost.java:2: error:  expected
import : import java.util;
        ^
./com/example/BlogPost.java:2: error: ';' expected
import : import java.util;
               ^
./com/example/BlogPost.java:2: error: class, interface, or enum expected
import : import java.util;
                    ^
./com/example/BlogPost.java:2: error: class, interface, or enum expected
import : import java.util;
                     ^
./com/example/BlogPost.java:24: error: class, interface, or enum expected
    public String getAuthor() {
           ^
./com/example/BlogPost.java:26: error: class, interface, or enum expected
    }
    ^
./com/example/BlogPost.java:28: error: class, interface, or enum expected
    public String getTitle() {
           ^
./com/example/BlogPost.java:30: error: class, interface, or enum expected
    }
    ^
./com/example/BlogPost.java:32: error: class, interface, or enum expected
    public String getBody() {
           ^
./com/example/BlogPost.java:34: error: class, interface, or enum expected
    }
    ^
./com/example/BlogPost.java:36: error: class, interface, or enum expected
    public String getCategory() {
           ^
./com/example/BlogPost.java:38: error: class, interface, or enum expected
    }
    ^
./com/example/BlogPost.java:40: error: class, interface, or enum expected
    public Date getCreationDate() {
           ^
./com/example/BlogPost.java:43: error: class, interface, or enum expected
}
^
./com/example/BlogPost.java:21: error: cannot find symbol
    return "BlogPost: \""+mTITLE + "\" -@" + mAUTHOR;
                          ^
  symbol:   variable mTITLE
  location: class BlogPost
./com/example/BlogPost.java:21: error: cannot find symbol
    return "BlogPost: \""+mTITLE + "\" -@" + mAUTHOR;
                                             ^
  symbol:   variable mAUTHOR
  location: class BlogPost
17 errors
William Li
William Li
Courses Plus Student 26,868 Points

edited the post for proper code formatting.

package com.example; import : import java.util; import java.util.Date;

public class BlogPost { private String mAuthor; private String mTitle; private String mBody; private String mCategory; private Date mCreationDate;

public BlogPost(String author, String title, String body, String category, Date creationDate) {
  mAuthor = author;
  mTitle = title;
  mBody = body;
  mCategory = category;
  mCreationDate = creationDate;
}

@Override public String toString(){ return "BlogPost: \""+mTITLE + "\" -@" + mAUTHOR; } } public String getAuthor() { return mAuthor; }

public String getTitle() {
  return mTitle;
}

public String getBody() {
  return mBody;
}

public String getCategory() {
  return mCategory;
}

public Date getCreationDate() {
  return mCreationDate;

}package com.example; import : import java.util; import java.util.Date;

public class BlogPost { private String mAuthor; private String mTitle; private String mBody; private String mCategory; private Date mCreationDate;

public BlogPost(String author, String title, String body, String category, Date creationDate) {
  mAuthor = author;
  mTitle = title;
  mBody = body;
  mCategory = category;
  mCreationDate = creationDate;
}

@Override public String toString(){ return "BlogPost: \""+mTITLE + "\" -@" + mAUTHOR; } } public String getAuthor() { return mAuthor; }

public String getTitle() {
  return mTitle;
}

public String getBody() {
  return mBody;
}

public String getCategory() {
  return mCategory;
}

public Date getCreationDate() {
  return mCreationDate;

}

package com.example; import : import java.util; import java.util.Date;

public class BlogPost { private String mAuthor; private String mTitle; private String mBody; private String mCategory; private Date mCreationDate;

public BlogPost(String author, String title, String body, String category, Date creationDate) {
  mAuthor = author;
  mTitle = title;
  mBody = body;
  mCategory = category;
  mCreationDate = creationDate;
}

@Override public String toString(){ return "BlogPost: \""+mTITLE + "\" -@" + mAUTHOR; } } public String getAuthor() { return mAuthor; }

public String getTitle() {
  return mTitle;
}

public String getBody() {
  return mBody;
}

public String getCategory() {
  return mCategory;
}

public Date getCreationDate() {
  return mCreationDate;

}

i am falling to sen the whole code l wil try again

George Sideris
PLUS
George Sideris
Courses Plus Student 3,712 Points

If you could tell us in which part of your cource you are ... I think in all cources you don't need to import anything ...

on java objects the question Override the toString method from java.lang.Object and make it return the following information: "BlogPost: TITLE by AUTHOR"

George Sideris
PLUS
George Sideris
Courses Plus Student 3,712 Points

Sorry I can't find the question ... But you should check the brackets and try to not @OVERRIDE the method toString :

public String toString() { return "Text "; }