• Post Reply Bookmark Topic Watch Topic
  • New Topic

another compiling error

 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am making mvc model

classes are organized under clasess

com->phoneDir.class ( normal java, model)
com->testing.class (servlet, controler)

and for model i have code like

package com;
import java.util.*;

public class phoneDir
{

public List getPhone(String name)
{
List phone=new ArrayList();

if (name.equals("amit"))
{
phone.add("9873085014");
phone.add("01122721799");

}
else
{
phone.add("unknown");
phone.add("unknown");
}
return phone;
}

}



and for controller i have code like

package com;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import phoneDir;

public class testing extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException
{
res.setContentType("text/html");

PrintWriter out =res.getWriter();
out.println("<html> Hack the matrix </html>");
out.println(req.getParameter("name"));
out.println(req.getParameter("empid"));

phoneDir ph= new phoneDir();
List phone_no =ph.getPhone(req.getParameter("name"));

Iterator it= phone_no.Iterator();
while(it.hasNext())
{
out.println("<br> "+ it.next());
}
}
}


...and model got compile but ...controller is not getting compiled and following errro si comming..



C:\Tomcat5014\webapps\jsp_prac\WEB-INF\classes\com>javac testing.java
testing.java:6: '.' expected
import phoneDir;
^
1 error


can anybody tell me why ?

==========================================================


if change order of package like

com->phoneDir.class (model)
org->testing.class (servlet, controller)

and under testing.class
i change "import com.phoneDir;" or "import com.*;"

i got follwing error while compiling.. testing.java


C:\Tomcat5014\webapps\jsp_prac\WEB-INF\classes\org>javac testing.java
testing.java:6: package com does not exist
import com.*;
^
testing.java:19: cannot resolve symbol
symbol : class phoneDir
location: class org.testing
phoneDir ph= new phoneDir();
^
testing.java:19: cannot resolve symbol
symbol : class phoneDir
location: class org.testing
phoneDir ph= new phoneDir();
^
testing.java:22: cannot resolve symbol
symbol : method Iterator ()
location: interface java.util.List
Iterator it= phone_no.Iterator();
^
4 errors



---
why i m getting such errors ?
[ July 24, 2005: Message edited by: amit taneja ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the class phoneDir is in the package com, ihe statement should read "import com.phoneDir". The way you have it now would be correct only if phoneDir was not in any package.
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i put phoneDir.class directly under classes folder

and call from com->testing.java

and write only

import phoneDir;

the following error comes..


C:\Tomcat5014\webapps\jsp_prac\WEB-INF\classes\org>javac testing.java
testing.java:6: '.' expected
import phoneDir;
^
1 error


why... ?
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit,
Ulf has aldready suggested you to change,
to,

because both the classes are in the same package com

Another error I see in your code is here

The Interface List does not have any method Iterator()
Check the List API
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Abdulla Mamuwala

please try yourself.. seriously i made my effort and still not able to compile testing.java

i have use this
import com.phoneDir;

and again i m facing this error

C:\Tomcat5014\webapps\jsp_prac\WEB-INF\classes\com>javac testing.java
testing.java:3: cannot resolve symbol
symbol : class phoneDir
location: package com
import com.phoneDir;
^
testing.java:21: cannot resolve symbol
symbol : class phoneDir
location: class com.testing
phoneDir ph= new phoneDir();
^
testing.java:21: cannot resolve symbol
symbol : class phoneDir
location: class com.testing
phoneDir ph= new phoneDir();
^
3 errors



[ July 24, 2005: Message edited by: amit taneja ]
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit I compiled your source code and it compiles fine. Check your directory structure again I think something is wrong in the location you store your source code and compiled files. I see you are compiling your testing.java from the classes folder. I don't understand why you are doing that. Now just follow the directory structure I give below.

1>Make and put your source files testing.java and phoneDir.java in,
C:\Tomcat5014\webapps\jsp_prac\WEB-INF\src\com\phoneDir.java
C:\Tomcat5014\webapps\jsp_prac\WEB-INF\src\com\testing.java

2>compile your code i.e.
C:\javac -d Tomcat5014\webapps\jsp_prac\WEB-INF\classes\com Tomcat5014\webapps\jsp_prac\WEB-INF\src\com phoneDir.java
C:\javac -d Tomcat5014\webapps\jsp_prac\WEB-INF\classes\com Tomcat5014\webapps\jsp_prac\WEB-INF\src\com testing.java

The -d option will tell the compiler to put the .class file in the classes directory within the correct package structure.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Changing "import phoneDir" to "import com.phoneDir" and "Iterator it= phone_no.Iterator();" to "Iterator it= phone_no.iterator();" enables your classes to compile correctly.

My command line was:
javac -cp c:\j2sdkee1.3.1\lib\j2ee.jar com/*.java
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys..

Thanx a ton for making effort for giving reply... seriously hatsoff to ur effort...

but to be honest now i will not force you to reply because

i am still not able to compile the program... i don't know what the hell is wrong with my computer ..

it is still showing errors now i have put in src directory

C:\Tomcat5014\webapps\jsp_prac\WEB-INF\src\com>javac testing.java
testing.java:3: cannot resolve symbol
symbol : class phoneDir
location: package com
import com.phoneDir;
^
testing.java:21: cannot resolve symbol
symbol : class phoneDir
location: class com.testing
phoneDir ph= new phoneDir();
^
testing.java:21: cannot resolve symbol
symbol : class phoneDir
location: class com.testing
phoneDir ph= new phoneDir();
^
3 errors


your replies are optional but i upset..
and sad too
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 - you shouldn't have to import classes from the same package. Remove the import of phoneDir from testing.java

2 - Sounds like you are missing the "current directory" from your classpath.


In directory C:\Tomcat5014\webapps\jsp_prac\WEB-INF\classes\ try:
javac -classpath %CLASS_PATH%;. com/testing.java

Hope this helps,
evnafets
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still not compiling...i have tried all things ...seriously i am fedup ?

what should i do guys
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Tomcat5014\webapps\jsp_prac\WEB-INF\src\com>javac testing.java


You are in the wrong directory. A simple "cd .." will fix that, and then everything should compile just fine.
 
Naapa Sekhar Ramesh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Tomcat5014\webapps\jsp_prac\WEB-INF\src\com>javac testing.java


Ulf Dittmer, you are absolutely right.
To be precise about command

C:\Tomcat5014\webapps\jsp_prac\WEB-INF\src>javac com/testing.java

This will do
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it got compiled ..
thanx....

I mean thanx 100 times for ur reply...

but please tell me why its not running and why it run this time.
atleast i should learn something ...


Best regards,
amit
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!