Results 1 to 8 of 8
Thread: Compile: symbol not found
- 06-22-2008, 05:14 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 3
- Rep Power
- 0
Compile: symbol not found
Hi,
I'm realy new to java, I have a code that i need to compile but when i try it it give me error symbol not found
My project consist 3 files:
DbCon.java MemberArticle.java and ArticleDB.java
I can compile DbCon and MemberArticle but I can't compile ArticleDB.java and here is the ArticleDB code:
DbCon.java:Java Code:package MyClass; import java.sql.*; import MyClass.MemberArticle; import MyClass.DbCon; public class ArticleDB { private Connection conn; private PreparedStatement pstmt; private ResultSet rs; //1. »ý¼ºÀÚ ¼±¾ð : Connection ÀνºÅϽº°¡ »ý¼ºµÇµµ·Ï ÇÑ´Ù. public ArticleDB() throws SQLException { conn = DbCon.getConnection(); } //2. DB¿¡ ·¹ÄÚµå °»½ÅÀ» À§ÇÑ updateRecord() ¸Þ¼Òµå ¼±¾ð // @param : MemberArticle // @return : void public void updateRecord(MemberArticle article) throws SQLException { String sql = "UPDATE kagebu SET day=?, month=?, year=?, trans=?, info=?, amount=?, id=? WHERE id=?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, article.getDay()); pstmt.setString(2, article.getMonth()); pstmt.setString(3, article.getYear()); pstmt.setString(4, article.getTrans()); pstmt.setString(5, article.getInfo()); pstmt.setString(6, article.getAmount()); pstmt.setString(7, article.getId()); pstmt.executeUpdate(); } //3. ÁöÁ¤µÈ id¿¡ ÇØ´çÇÏ´Â DB¿¡ ÀúÀåµÈ ·¹Äڵ带 ¹Ýȯ // @param : String // @return : MemberArticle public MemberArticle getRecord(String id) throws SQLException { String sql = "SELECT day, month, year, trans, info, amount,id FROM kagebu WHERE id=?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, id); rs = pstmt.executeQuery(); rs.next(); // ¹ÝȯµÇ´Â record´Â ¿ÀÁ÷ Çϳª. MemberArticle article = new MemberArticle(); article.setDay(rs.getString("day")); article.setMonth(rs.getString("month")); article.setYear(rs.getString("year")); article.setTrans(rs.getString("trans")); article.setInfo(rs.getString("info")); article.setAmount(rs.getString("amount")); article.setId(rs.getString("id")); return article; } //4. openµÈ ¸ðµç ¿¬°áÀÚ Á¤º¸¸¦ Á¦°Å // @param is'nt // @return void public void close() throws SQLException{ if(rs != null) rs.close(); if(pstmt != null) pstmt.close(); if(conn != null) conn.close(); } }
MemberArticle.java:Java Code:package MyClass; import java.sql.*; public class DbCon { final static String URL = "jdbc:mysql://localhost:3306/housekeeping?useUniCode=true&characterEncoding=euckr"; final static String USER = "user"; final static String PASSWORD = "pass"; static { try { Class.forName("com.mysql.jdbc.Driver"); }catch (ClassNotFoundException e) { System.out.println(e.getMessage()); } } public static Connection getConnection() throws SQLException { return DriverManager.getConnection(URL, USER, PASSWORD); } }
weird thing is my friend said he can compile it with no error but when i get the compiled files and put it on my server it will give me error no symbol found error on the webbrower so i dont know which part i'm wrong here maybe my computer configuration? if yes what should i change? I already put the proper classpath that needed but still no luck.Java Code:package MyClass; public class MemberArticle { private String id; private String day; private String month; private String year; private String trans; private String info; private String amount; //¼±¾ðµÈ ¸â¹öµé¿¡ ´ëÇÑ getter¿Í setter ¸Þ¼Òµå¸¦ ¼±¾ðÇØ ÁØ´Ù. public void setDay(String day) { this.day = day; } public void setMonth(String month) { this.month = month; } public void setYear(String year) { this.year = year; } public void setTrans(String trans) { this.trans = trans; } public void setInfo(String info) { this.info = info; } public void setAmount(String amount) { this.amount = amount; } public void setId(String id) { this.id = id; } public String getDay(){ return day; } public String getMonth(){ return month; } public String getYear(){ return year; } public String getTrans(){ return trans; } public String getInfo(){ return info; } public String getAmount(){ return amount; } public String getId(){ return id; } }
Compile error:
ThanksJava Code:---------- Java Compile ---------- X:\MyClass\ArticleDB.java:4: cannot resolve symbol symbol : class MemberArticle location: package MyClass import MyClass.MemberArticle; ^ X:\MyClass\ArticleDB.java:5: cannot resolve symbol symbol : class DbCon location: package MyClass import MyClass.DbCon; ^ X:\MyClass\ArticleDB.java:22: cannot resolve symbol symbol : class MemberArticle location: class MyClass.ArticleDB public void updateRecord(MemberArticle article) throws SQLException { ^ X:\MyClass\ArticleDB.java:43: cannot resolve symbol symbol : class MemberArticle location: class MyClass.ArticleDB public MemberArticle getRecord(String id) ^ X:\MyClass\ArticleDB.java:15: cannot resolve symbol symbol : variable DbCon location: class MyClass.ArticleDB conn = DbCon.getConnection(); ^ X:\MyClass\ArticleDB.java:53: cannot resolve symbol symbol : class MemberArticle location: class MyClass.ArticleDB MemberArticle article = new MemberArticle(); ^ X:\MyClass\ArticleDB.java:53: cannot resolve symbol symbol : class MemberArticle location: class MyClass.ArticleDB MemberArticle article = new MemberArticle(); ^ 7 errors Output completed (2 sec consumed)Last edited by zuan; 06-22-2008 at 05:17 PM.
- 06-22-2008, 06:07 PM #2
Hi
Its very simple error.
You dont have to explicitly import the classes of same package.
So when u r trying to import MyClass.MemberArticle, its throwing the error
and where ever u r using that class its throwing the same error.
Remove that import stmt.To finish sooner, take your own time....
Nivedithaaaa
- 06-23-2008, 09:43 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Better to refer some documents on these basis. Sun's official website have a grate/simple explanation on those things.
- 06-23-2008, 04:39 PM #4
Member
- Join Date
- Jun 2008
- Posts
- 3
- Rep Power
- 0
Already done that it only remove the 1st 2 error the other 5 still remain
no luck have being digging around but no luck at all, when I try to use -verbose i can see that javac dont even search the -classpath that I manually added :( I'm stuck and dont know what the cause ... :mad:
- 06-23-2008, 05:04 PM #5
Hello Zuan,
to remove all the errors u need to remove
import MyClass.DbCon;
with
import MyClass.MemberArticle;
as u can see clearly both r in the same package as i said u dont have to import them.
I think that was the problem.To finish sooner, take your own time....
Nivedithaaaa
- 06-24-2008, 03:41 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Why don't you try all those thing on command prompt and the Notepad. I think it's much better to use in the beginning. Even on the command prompt you can easily find those errors. Not much explanation you get there, but it's worth at all.
- 06-24-2008, 05:08 AM #7
Member
- Join Date
- Jun 2008
- Posts
- 3
- Rep Power
- 0
I'm using command prompt + textpad
Nope still the same :p
Originally Posted by Niveditha
btw i manage to find out why it wont compile, the directory for all the files must be in a directory which have exact name as the package for this to work and i didnt know that :eek: :p
thank for the input :cool:
- 06-24-2008, 05:17 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
This is optional. I mean, for a example if your class MemberArticle in a folder named MyClass then you have to import them as a package.
if you want to use all classes on that folder you import all of them as follows.Java Code:import MyClass.MemberArticle;
If all classes in the same folder(in Java also called as a package) no need to import any class in another class.Java Code:import MyClass.*;
Similar Threads
-
GeoPoint Not found
By nvidia in forum NetBeansReplies: 2Last Post: 05-28-2008, 09:31 PM -
symbol not found error
By rmartyce in forum New To JavaReplies: 1Last Post: 05-23-2008, 05:58 AM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 08:30 AM -
could not be found in the registry
By alam99 in forum EclipseReplies: 0Last Post: 01-08-2008, 08:21 AM -
404 Not Found
By mary in forum Java ServletReplies: 5Last Post: 11-07-2007, 10:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks