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
Nikhil Rai
15,391 PointsCannot find the class from package
I tried alot of ways but I am sure I am missing something. I was following along with the video tutorials for packages and I am trying to implement the examples in local environment and compiling and running with command prompt on windows 10. (Please dont care about the names, I changed them just while practicing, I dont think that can be a reason for this.)
I am using NOTEPAD++ to practice the codes as I feel it makes me even better when it comes to practice debugging.
I created a package which is in the location: C:\Users\ruudr_000\Documents\ASSIGNMENTS\JAVA_Treehouse\Package_example\com\nikhil\Tweet.java
package com.nikhil;
import java.util.Date;
public class Tweet{
private String mAuthor;
private String mDescription;
private Date mDate;
public Tweet(String author, String desc, Date dDate){
//constructor
mAuthor = author;
mDescription = desc;
mDate = dDate;
}
public String getAuthor(){
return mAuthor;
}
public String getDescription(){
return mDescription;
}
public Date getDate(){
return mDate;
}
}
then I created the Example.java in location: C:\Users\ruudr_000\Documents\ASSIGNMENTS\JAVA_Treehouse\Package_example\Example.java
import com.nikhil.Tweet;
import java.util.Date;
public class Example{
public static void main(String[] args){
Tweet mTweet = new Tweet(
"NikhilRai",
"Description is a bit complicated as I do not have a twitter account",
new Date(1449224173000L)//this is an epoch time converted for current date
);
System.out.printf("New tweet has been created : %s", mTweet);
}
}
Please if you get any idea out of it, help me. Thank you.
[UPDATE]: I tried to run it in the workspace and it worked perfectly fine. But now my question is, how will I be able to run it in a local environment and what may be the issue that is causing the errors when kusing it from command line on my pc.? Any suggestions ?
[MOD: added ```java formatting around code blocks -cf]
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHikhil,
have you imported the Tweet class into Example? If the Example class is outside the com - package you need to do so ...
import com.nikhil.Treet;