|
|
Frequently Asked Questions
Here you can find answers to questions students asked in the previous years.
Please read them carefully before posting in the newsgroup.
Organizational Questions
-
Can I change my password?
No, we are sorry. You cannot change your password for technical reasons.
-
I would like to use
ant
and the
build.xml
file but don't want to use jikes. What do I have to change in the
build.xml
file?
At the beginning of the
build.xml
file you find the line:
<property name="build.compiler" value="jikes"/>
Change the value
jikes
to
classic.
This instructs
ant
to use javac instead of jikes. The correct line would then be:
<property name="build.compiler" value="classic"/>
General Java programming questions:
-
I try to access the value
IConstants.XYZ
using the
getProperty()
method but I don't get the value I specified in the property file.
Did you type
getProperty("IConstants.XYZ")
? This does not work since your are looking for the property named "IConstants.XYZ" which does not exist. Instead you are looking for the property whose name is stored in the variable
IConstants.XYZ
. This means you have to use
getProperty(IConstants.XYZ)
without
quotation marks ("").
-
Man, when I try to compile my java code I receive an
InvocationTargetException
or an
IllegaAccessException
.
The reason for this might be that you did not declare the method to be
public.
In this case, the method has package scope which means it is visible only within its package. For example, the following code snippet for the method
myGreatMethod()
will cause an exception if called from outside the package:
void myGreatMethod() {
// ... some code here ...
}
Instead, you should declare the method
public
as shown below:
public void myGreatMethod() {
// ... some code here ...
}
-
Damn, I keep getting
ClassNotFoundException
error messages.
This most likely is a
CLASSPATH
problem. Make sure your classpath includes the directory containing your classes and the required library
*.jar
files. If your
CLASSPATH
seems to be correct, the only other possible explanation is that you placed your class in the wrong package, i.e., the first line of your source file contains a wrong package definition.
-
Sh$%*t., my variable always contains
null
although I set it before.
Take a deep breath. Take another one. Now check that you did not define a global AND a local variable with the same name!! Believe it or not, we have seen this a couple of times.
-
Holly Molly, whenever I compare objects with
toString()
, the comparison does not work!
Now wait a moment. This is completely correct behavior - you must NEVER compare the output of
toString()
of two objects!
toString()
gives you a string representation of the object reference only! If you still do not understand the problem, consult the Java tutorial ('Learning the Java language').
Questions concerning Lab 1:
-
I try to run the first lab example and get the
message:
Could not create implementation
class via reflection!
.
Is the constructor of your
at.ac.tuwien.infosys.rnue.implementation.ShareMeImpl
declared
public
?
-
I try to run the first lab example and get the
message:
Could not instantiate
implementation class (or other
error)!
Does your implementation of the
at.ac.tuwien.infosys.rnue.implementation.ShareMeImpl
class implement the
IShareMe
interface?
-
I try to run the first lab example and get the
message:
java.lang.ClassNotFoundException:
Oh well, the task description says: "Create a class called
at.ac.tuwien.infosys.rnue.implementation.ShareMeImpl
. This
means that the class
ShareMeImpl
should be
in the package
at.ac.tuwien.infosys.rnue.implementation
. Ok,
but what does this mean to me? This means you should declare the class
to be part of this package. And how do I do this? The
first
code line in your
ShareMeImpl.java
has to declare this:
package at.ac.tuwien.infosys.rnue.implementation;
Questions concerning Lab 2:
-
Here is a newsgroup article (in German) from a previous year that nicely outlines the difference between
Naming.rebind()
and
Registry.rebind()
.
Hallo,
zunächst einmal zur Registry: eine RMI Registry ist ein einfaches Name Service, bei dem man Referenzen zu remote Objekten unter einem Namen ablegen kann. Andere können dann ein lookup machen und die Referenz erhalten. Eine Registry kann man nun als eigenen Prozess (extern zum Programm) oder innerhalb des eigenen Programms (so wie im Fall von ShareMe) starten. Dazu verwendet man
LocateRegistry.createRegistry(port)
. Man hat dann also ein eigenes kleines Name Service am entsprechenden Port. Eine Registry muss man auf jeden Fall erstellen, sonst kann man weder
rebind()
noch
lookup()
Operationen sinnvoll verwenden.
Nun kurz zu RMI Namen bzw. URLs: generell hat ein RMI URL die Form
"rmi://" + registryHost + ":" + registryPort + "/" + ServiceName
. Dabei ist der erste Teil nur zum Finden der Registry notwendig, der ServiceName ist dann der registrierte Name des Service.
Jetzt aber zur Verwendung der Registry. Das Registry Interface, das man von
LocateRegistry.createRegistry()
zurückbekommt ist eine direkte Referenz auf die Registry. Man kann dort jetzt
rebind()
und
lookup()
Methoden aufrufen. Dabei ist aber zu beachten, dass man ja schon weiss, um welche Registry es sich handelt, man braucht also keinen vollständigen RMI URL mehr sondern nur noch den Service Namen, z.B.:
Registry localRegistry = LocateRegistry.createRegistry(rPort);
RMIServer server = new RMIServer();
localRegistry.rebind("TestRMIServer", server);
// das funktioniert
Remote r = localRegistry.lookup("TestRMIServer");
// das nicht ...
Remote r2 = localRegistry.lookup("rmi://localhost:" + rPort + "/TestRMIServer");
In der Regel hat man aber keine direkte Referenz auf die Registry, da man sich ja normalerweise in einem anderen Prozess befindet. Dafür ist die Naming Klasse gedacht. Dort hat man die gleichen Methoden zur Verfügung, braucht aber keine direkte Referenz auf die Registry sondern verwendet eben den oben besprochenen RMI URL. Man kann also das gleiche Verhalten wie im obigen Beispiel durch folgendes Code-Stück erreichen (beachten Sie, dass zwar eine Registry erzeugt wird, aber später nie wieder direkt über die Referenz darauf zugegriffen wird):
Registry localRegistry = LocateRegistry.createRegistry(rPort);
RMIServer server = new RMIServer();
Naming.rebind("rmi://localhost:" + rPort + "/TestRMIServer", server);
// das funktioniert jetzt nur mehr, wenn die Registry am lokalen
// Host und am default Port (1099) läuft, entspricht also
// lookup("rmi://localhost:1099/TestRMIServer")
Remote r = Naming.lookup("TestRMIServer");
// das funktioniert dafür nicht nur vom lokalen Prozess sondern immer
Remote r2 = Naming.lookup("rmi://localhost:" + rPort + "/TestRMIServer");
Im Falle des Lab, könnte man nun also entweder Naming.rebind() mit einem vollständigen RMI URL verwenden, oder aber localRegistry.rebind() mit nur dem Service Namen. Für das lookup() hingegen, muss man immer Naming und vollständige RMI URLs verwenden, das man ja keine Referenzen auf die Registries der anderen ShareMe Peers hat. Um unnötige Verwirrungen zu vermeiden, haben wir in der Doku immer die Verwendung von Naming angegeben.
Questions concerning Lab 3:
Questions concerning Lab 4:
-
I have just implemented the
ShareMeEntry
and try to test the search functionality with the
HTTPServerTester
but it does not work. Why?.
The
HTTPServerTester
only registers two
DocumentEntry
request handlers for the
IConstants.DOWNLOAD_PREFIX
and the
IConstants.DOC_PREFIX
. No
ShareMeEntry
is registered. To test the search functionality you have to finish the implementation of Lab4 and start your ShareMe peer.
-
What the hell is going on? I implemented the
HTTPServerImpl
and whenever I try to Test it with the
HTTPServerTester
I receive the following message:
Could not create implementation class via reflection! Aborting!
Well, you should continue reading the error message! It also says:
java.lang.NoSuchMethodException: at.ac.tuwien.infosys.rnue.implementation.http.HTTPServerImpl.(java.lang.Integer)
So, does your constructor take an
int
variable instead of a
java.lang.Integer
object as parameter? Ok, here we have the problem. The constructor of the
HTTPServerImpl
class MUST take an
java.lang.Integer
object. Otherwise we could not instantiate it via reflection.
-
I got the grading result from lab 4 and your mail says that the header date has not the correct format. How should it look like?
Did you use the
RFC1123DateFormatter:
to format the date? This should solve your problem. The date should then look like the following example:
Son, 15 Dec 2002 14:57:00 GMT
|
|