|
First thing is that all your tests are the wrong way round (and logically wrong I suspect), you should check the variable is not null before using it as a reference to a method thus:
if (name == null || name.isEmpty()) {
if (name != null && !name.isEmpty()) {
I am not sure how you would condense the two loops any more as they appear to be independent of each other.
|
|
|
|
|
Is this entered from a GUI or is this object coming from some API?
For a GUI you can also use a GUI sided validation. You can e.g. use a KeyListener and validate the entered value right away.
For an API side validation I would suggest a Validation Layer which has to be passed before the data is used.
Your code - as Richard already stated - is a bit mixed up. Here is a valid suggestion:
private void doCheck() {
if (name != null && name != "") {
for (String year : years) {
if (year != null && year != "" ) {
try{
int i = Integer.parseInt(year);
}
catch(Exception oException){
}
}
}
for (String studyChoice : studyChoices) {
if (studyChoice!=null && studyChoice != ""){
}
}
}
else{ }
}
|
|
|
|
|
i am trying to design a simulation with java for my project title location-aware communication to achieve social inclusion and social responsibility which is a telecommunication project which conveys messages to subscribers that are mostly affected or benefited by the piece of information and shows boosters that are necessary to make this possible.
|
|
|
|
|
We believe you. What is the question?
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Structure - it's all about structure.
No matter if face to face, while working or anywhere else.
Especially when writing some.
|
|
|
|
|
Simulation with Java
If you've never failed... You've never lived...
|
|
|
|
|
Is there a question in all that babble somewhere?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hello
Is there an article to open an excel file and write through jxl files.
Every time I try to write into excel file a new file is created instead of opening the old file.
Pritha
|
|
|
|
|
prithaa wrote: Is there an article to open an excel file Quite possibly, have you tried a Google search?
prithaa wrote: a new file is created instead of opening the old file. Without seeing your code I don't think we can guess what you may be doing wrong.
[edit]
This method[^] is probably what you are looking for.
[/edit]
|
|
|
|
|
thanks
but the above link is not opening
my problem was the following
InputStream inp = new FileInputStream("d:/Writefile.xls");
WorkbookSettings ws = new WorkbookSettings();
Workbook wb = Workbook.getWorkbook(inp, ws);
Sheet sheet = wb.getSheet(0);
Number number;
number = new Number(0, 0, 453.25, times);
((WritableSheet) sheet).addCell(number);
wb.close();
The above code doesnt add the cell to the given file just opens the file.I get DispatchUnCaughtException for the line
((WritableSheet) sheet).addCell(number);
Thanks for the reply
Pritha
|
|
|
|
|
|
thanks Richard
but a
WritableWorkbook creates a new workbook and has no method which opens a workbook
Pritha
|
|
|
|
|
This method[^] creates one. May I suggest you go through all the documentation to check which methods are required to create the objects you are trying to work with.
|
|
|
|
|
thanks for the article
but i cant still open a writableworkbook .i can write on a new
workbook
but cant write on an existing workbook
I didnt find any method doing that either in writableworkbook
regards
Pritha
|
|
|
|
|
|
prithaa wrote: thanks for the article
I did not provide one, I wonder what you have been looking at.
prithaa wrote: but i cant still open a writableworkbook
Did you follow my advice and read all the documentation in the link I gave you? It clearly shows how to create a writeable workbook from an existing file.
|
|
|
|
|
yes i did read the link u sent and looked at the
class writablework
but there is no method which opens an existing .xls file
Regards
Pritha
|
|
|
|
|
Sorry, previous link was not correct owing to HTML frame. However, I think this one[^] is the best you will get.
|
|
|
|
|
thanks for replying
Workbook workbook = Workbook.getWorkbook(new File("d:/Writefile.xls"));
WritableWorkbook copy = Workbook.createWorkbook(new File("d:/Writefile1.xls"), workbook);
copy.write();
WritableSheet sheet = copy.getSheet("Report2");
Number number;
number = new Number(0, 0, 453.25, times);
sheet.addCell(number);
copy.write();
copy.close();
I want to open an existing file and add a cell to an existing sheet. The above code opens the file but the cell editing doesnt happen.
Regards
pritha
|
|
|
|
|
Sorry, no idea why that's happening; I think you may need to re-check the documentation and work with your debugger.
|
|
|
|
|
Thankyou Richard for your help
|
|
|
|
|
Just for the record, I have never used these packages[^]; all the information I gave you I found by using Google and reading the Javadocs.
|
|
|
|
|
Hi, I have a class for uploading a file with a method called uploadFile(), which uploads the user's file to the server in a directory like this:
C:/apache-tomcat-6.0.35/temp/accountName/username/filename
Before uploading the file, it calls the method createDirectory() which creates the above directory path if it doesnt already exist. Here is the code for it:
public void createDirectory(String accountName, String username){
if (new File("C:\\apache-tomcat-6.0.35\\temp\\" + accountName + "\\" + username).exists() == false) {
new File("C:\\apache-tomcat-6.0.35\\temp\\" + accountName + "\\" + username).mkdirs();
}
}
I want to test that it creates a directory if it doesnt exist, without actually creating the directory (so using Mockito).
I'm struggling to get to grips with Mockito and would appreciate any assistance with it.
Thanks
|
|
|
|
|
I haven't work with that before. However, why don't you read there documentations and give a try?
If you've never failed... You've never lived...
|
|
|
|
|
Im facing one problem in streaming data capture for reading the broadcast during multithreading, pls help if u get time,
Actually there is one class which is reading data from one of the udp socket another class is their which accepts the tcp connection from every client request and creates a thread for every client and request the same udp class for data the thing is working with 1st thread which gets created but when i request with another client from another pc/ip the packets get losted to the 2nd client/thread
I have made a workaround by creating a list where im storing the Threads outputstream object
and looping it to send the data to all the client but this is just temporary as it ll delay the packets if clients/connections gets increased
pls suggest if required will share the code.
thanks in advance
|
|
|
|