|
The code looks alright. the only culprit could be the 2 functions
1. When you are constructing the fName
2. When you are setting the File name.
|
|
|
|
|
Jim Crafton wrote: Have I missed something absurdly obvious?
Errr...why don't you just use log4j?
|
|
|
|
|
That's what I thought too. LOG4J is simple, works fine and should be the choice.
regards Torsten
I never finish anyth...
|
|
|
|
|
Using a library is ok but while some1 is coding such obv modules basic coding too shall work. Use a simpler library can never be an excuse.
|
|
|
|
|
hi everyone!my project is about coding nurse rostering using Clonal Selection Algorithm in java..it's only for one ward and have 30 nurses in this ward..i need to make this roster for 14 days..anyone can help me please?
|
|
|
|
|
Ok I guess you could book a plain ticket to Java, get out a pen and some paper when you are there and then start writing down the duty roster. After you are finished you could mail in in to the hospital.
Or if you have a specific technical question / problem about Java and not please build my sh*t for me cause I'm to lazy you can ask us.
|
|
|
|
|
hints:
- the week has 7 days
- a working day has usually 8 hours (9 - 1h pauses)
- a night shift can be longer (16h to make it simple?).
- every nurse has to have 2 days off a week
right? can you follow this?
then do
- plan
- design
- code
- test
And YES, this smells like homework. So implementation is up to you.
regards Torsten
I never finish anyth...
|
|
|
|
|
thanks for your suggestion..
|
|
|
|
|
Torsten has given you some excellent suggestions but I would just add this link[^] to help with the design aspects.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I am attempting to generate a compile-time error if a subclass does not define a specific static field with a type subclassed from a defined Class field in the annotation. For example:
import java.lang.annotation.*;
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
@Inherited
public @interface RequiredStaticField {
public String name();
public Class<?> type();
}
@RequiredStaticField(name="StaticField", type=Number.class)
public class MyClass {
private static Integer StaticField;
}
The classes above should validate and compile. However, I am having trouble determining if "Integer" is a subtype of "Number" in my AbstractProcessor implementation...
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.Types;
@SupportedAnnotationTypes("NAMESPACE.RequiredStaticField");
public class RequiredStaticFieldProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment environment) {
Set<? extends Element> elementsWithAnnotation =
environment.getElementsAnnotatedWith(RequiredStaticField.class);
for (Element elementWithAnnotation : elementsWithAnnotation) {
boolean isFound = false;
RequiredStaticMethod annotation = elementWithAnnotation
.getAnnotation(RequiredStaticMethod.class);
for (Element member : elementWithAnnotation.getEnclosedElements()) {
?>
// of member.asType(), or I need to iterate through the superclasses
// of member.asType(), or I need to convert annotation.type()
// to a TypeMirror object. Any Ideas?
isFound = Types.isSubType(member.asType(), annotation.type());
if (isFound) {
break;
} else {
// Display error about declaring with invalid type
}
}
if (!isFound) {
// Display error about missing field
}
}
return true;
}
}
I just can't figure out how to write a test to determine if a TypeMirror object is a subclass of a Class object. Thanks for any help,
Sounds like somebody's got a case of the Mondays
-Jeff
modified 15-Nov-11 20:33pm.
|
|
|
|
|
Figured it out: you can't access an annotation field of type Class<?> at compile-time. Attempting to do so results in a MirroredTypeException. Instead, pass the class in as a string containing the fully-qualified name of the type, and use the following code to get the TypeMirror for that type:
MyAnnotation annotation = elementWithAnnotation.getAnnotation(MyAnnotation.class);
Element typeDeclaration = processingEnv.getElementUtils().getTypeElement(annotation.type());
if (typeDeclaration == null) {
} else {
} Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I need to transfer file between client and server by using tcp socket as this code :
1- sender side ( server ):
spackage sender;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.util.Scanner;
public class Sender
{
private static ServerSocket serverSocket;
public static void main(String[] args)
{
System.out.println("Opening port...\n");
try
{
serverSocket = new ServerSocket(3000);
}
catch(IOException ioEx)
{
System.out.println("Unable to attach to port!");
System.exit(1);
}
try
{
Socket link = serverSocket.accept();
ObjectOutputStream outStream = new ObjectOutputStream(link.getOutputStream());
FileInputStream fileIn = new FileInputStream("image.GIF");
long fileLen = (new File("image.GIF")).length();
int intFileLen = (int)fileLen;
byte[] byteArray = new byte[intFileLen];
fileIn.read(byteArray);
fileIn.close();
outStream.writeObject(byteArray);
}
catch(IOException e)
{
System.out.println("error...");
}
}
}
2- receiver side (Client):
package reciever;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Reciever
{
public static void main(String[] args) throws Exception
{
try
{
Socket link = new Socket("localhost",3000);
ObjectInputStream inStream = new ObjectInputStream(link.getInputStream());
byte[] byteArray = (byte[])inStream.readObject();
FileOutputStream outStream = new FileOutputStream("image.GIF");
outStream.write(byteArray);
link.close();
}
catch(IOException e)
{
System.out.println("error...");
}
}
}
and the image.GIF file found at the sender side but this code make error , I need solution for this problem as soon as , please .
|
|
|
|
|
lolostar wrote: I need solution for this problem as soon as
some suggestions:
1. start sooner
2. don't throw away the information exceptions are offering
3. explain what the problem is (use case, symptoms, ...)
|
|
|
|
|
It's time to play Guess The Problem.
Is it:
A - my code doesn't compile
B - it throws an exception at runtime
C - nothing happens when I run it
D - it triggers global thermonuclear war and the start of a new ice age
Press the button on your handset now, and let's see what the studio audience thinks...
|
|
|
|
|
Sir! Sir! Pick me Sir!
Is it global thermonuclear war?
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
the problem appear when the receiver receive file from the sender .
|
|
|
|
|
yes
|
|
|
|
|
But why is it still a secret?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
[mode=igor]
Shall I fire up the labotomy drill marther?
[/mode]
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
I think the salient information is that the programs build and run, but an error occurs. Is this correct?
If yes, then WHAT IS THE EXCEPTION?
Going by your garbled post, you think the file image.gif exists, but it can't be loaded by the sender. Correct?
What folder is the file in? Where is sender.jar in relation to it?
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
yes , the program is running but the error occur at the receiver side because the exception occurred when the receiver try to receive the transmitted file from the sender .
the image.gif found in the sender package and because the transmitted process complete successfully so I don't think the problem in the image file .
|
|
|
|
|
Here is a very basic suggestion which should help you. I would not recommend this in a real production application, but for your situation I think you may find it helpful.
Replace this section of code:
catch(IOException e)
{
System.out.println("error...");
}
with this:
catch (IOException e)
{
e.printStackTrace();
}
This will give you more information which will hopefully give you an idea of what is going wrong.
|
|
|
|
|
I may be wrong in the analysis of the problem but on the server code you are creating 2 handles of files simultaneously without closing one. Wont this be a problem.
|
|
|
|
|
Well, I'm working on an application that works as a server for a Ship Management System. And my boss had an idea to limit client number based on license. After brief discussion we agreed to with a licensing system where we distribute a license file that must be put in app dir that contain a definition regarding how many clients are allowed.
Now regarding that file, I'm thinking of creating a class that contains the info then serialize it. and distribute that file to client and read the file from my application. My questions are, what encryption should I use? Are there any better solution?
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
use dongles. Dongles @ Wikipedia[^]
With dongles you can control who uses the Software and how much copies are used.
The dongle should be handled as a chip card, a USB-Dongle opens a gate to get viruses and all kinds of other stuff onto the ship.
Also think of obfuscation -> encryption of the code.
regards Torsten
I never finish anyth...
|
|
|
|