• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Interface

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a problem with Interface. The Interface looks like this.
---------
package packageName;
import java.util.*;
public interface dateIntFace {
public int getCDate();
public String getYr();
public Vector getMDates();
}
-----------
I have a class "dateClss" which implements this interface. It has setter functions also in addition to the getter functions of the interface.
package packageName;
import java.util.Vector;
public class Dateclss implements dateIntFace {
private int cDate;
private String yr;
private Vector m_dates = new Vector();
public void setCDate(int sysDate) {cDate = sysDate;}
public void setYr(String s) {yr = s;}
public void setMDates(Vector v) {m_dates.add(v);}
public int getCDate(){return crDate;}
public String getYr() {return yr;}
public Vector getMDates() {return m_dates;}
}
Now, in another class, I create objects of Dateclss, add them to a vector and store this vector in session.
I retrieve them back in a JSP custom tag class. to retrive these values, I wrote the code like this
dates = session.getAttribute("dateObj");
Iterator i = dates.iterator();
while (i.hasNext())
{
dateIntFace dif = (dateIntFace)i.next();
int cd = dif.getCDate();
String syr = dif.getYr();
Vector v = dif.getMDates();
// I even tried Vector v = new Vector(); v = dif.getMDates();
}
when I do this, the int and string values are loading but its throwing error in retrieving getMDates(). I get runtime error. If I dont typecast it to Interface and typecast it to the class type, things are working fine but i get the warning of "object not serialized" for Dateclss object.
why is it not mapping a vector? why are things working fine when retrieving int and string values and why am i getting problem while retrieving a vector.
Can an interface have imports?
Can it throw variables of collection type?
Please let me know.
Thanks,
Padma.
[ December 01, 2003: Message edited by: N Padma ]
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't show how do you put in those vectors in your "dates". Interface cannot throw anything, and class can't too. It's methods who throw exceptions not objects or classes. Methods in interfaces and classes can throw exceptions. Regarding imports, imports are also not part of the class or interface. It's part of compilation process and they belong to file (that is why they are not part of class/interface block).
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And you can throw anything you want but it should be derrived from Exception or RuntimeException. And pershaps you are getting error about Serializable because all exceptions are indirectly derrived from Throwable (you should derrive from Exception) which implements Serializable interface. So the problem might be because you throwing objects that are not derrived from Exception and thus do not support Seriazable interface.
 
Padma Prasad
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help, Vladas. I have known what my problem is. I am gettig the problem with Serializable. will look into it now.
Thanks again,
Padma.
reply
    Bookmark Topic Watch Topic
  • New Topic