|
Your use of substring is correct, but the test for the String value is not:
DOB.substring(3,5) == "01"
This is wrong because you are testing to see if DOB.substring(3,5) and "01" are the same object instance. In fact, they are not. They are two different String objects so even if they both have the same value this test will return false. You want to use the equals method to test the String value.
String s1 = new String("01");
String s2 = new String("01");
if (s1 == s2)
if (s1.equals(s2))
|
|
|
|
|
Thanks David...that makes a whole lot more sense now!
This website is a great resource, and I appreciate the help. Software is the core of the computer industry. Ok well, that's another huge debate...
I've been studying programming for two years now, and I'm really loving it. A friend recommended this website to me, and I've yet to feel disappointed. I'm glad there are a few knowledgable (and willing) people to help out here!
I good friend once told me once that, "A sign of a good programmer, is someone who'll work an eight hour job. He'll come home, have dinner, and get behind his computer and continue coding."
Just a thought
|
|
|
|
|
Hi
I've been facing problems with this new type of connection, and I want some examples on how to establish a serial connection between my phone (SE w910i) and my laptop, through bluetooth. I'm not an expertise on this topic, even on this programming language. It was better if I could make java applets in C#
|
|
|
|
|
Hi guys,
I have had some java software written for me that hits a web address and passes through a date/time value in the format of:
YYYYMMDDHHmmSS
Most of the time the date/time comes through correctly... but for some reason it "randomly" sends a through date/time values that are 50 days in the future...
The data gets sent through every 15 seconds and the data will be correct at 10:00:00 but then 15 seconds later I'll get 17:30:22 50 days in advance... and then the date/time value increments by 15 seconds, but still 50 days the future... it will also then "randomly" come good again... now this isn't an odd one here and there, it's right for a while, then will run the rest of the day sending the wrong time...
Does this make sense...???
The problem is I can't reproduce it at will... I know, I know, I'm a programmer and that is the first thing I ask my users to do.. Give me repro steps... but I can't figure out how to reproduce it...
I've tried setting the phone date/time back to a time just before when it has happened in the past, but then the software just works.. it sends the correct time values right through the previous problem window...
Now the only other thing I could think of was that the phone does something "odd" with time calculations or stores the date/time in a funny way internally that wouldn't be necessarily visible to the developer...
I'm clutching at anything I can at the moment because my boss is starting to get shirty about this bug...
Here is the code that I'm told is being used to formulate the date/time value ready for sending via the URL:
private String getTimestamp() {
String time = "00000000000000";
try {
Calendar ca = Calendar.getInstance();
ca.setTime(new Date(System.currentTimeMillis()));
int year = ca.get(Calendar.YEAR);
String syear = Integer.toString(year);
int month = ca.get(Calendar.MONTH) + 1;
String smonth = month < 10 ? "0" + Integer.toString(month) : Integer.toString(month);
int day = ca.get(Calendar.DAY_OF_MONTH);
String sday = day < 10 ? "0" + Integer.toString(day) : Integer.toString(day);
int hour = ca.get(Calendar.HOUR_OF_DAY);
String shour = hour < 10 ? "0" + Integer.toString(hour) : Integer.toString(hour);
int min = ca.get(Calendar.MINUTE);
String smin = min < 10 ? "0" + Integer.toString(min) : Integer.toString(min);
int second = ca.get(Calendar.SECOND);
String ssecond = second < 10 ? "0" + Integer.toString(second) : Integer.toString(second);
time = syear + smonth + sday + shour + smin + ssecond;
} catch (Exception e) {
}
return time;
}
As stated in the Subject here... this is happening on two different Nokia 2323 phones... unfortunately I don't have another nokia phone to test this on to see if its a specific 2323 problem or a Nokia problem...
HELP ME PLEASE..!!!!
If anyone has a suggestin, no matter how crazy, I'm willing to try it out...
Has anyone ever come across this issue before...
If you need more clarification or have questions... shoot them through...
Thanks
** I'm not crazy.. Just ask my toaster **
|
|
|
|
|
I've run your code on my PC and it seems to work fine. The only thing I can suggest is to check the value returned from System.currentTimeMillis() which is being used to seed the calendar object.
It's time for a new signature.
|
|
|
|
|
G'day,
Thanks for the quick reply...
The code does work most of the time.. that's the problem... it'll work for minutes/hours/days, so a quick couple of tests will probably return a correct answer...
What do you mean to "check the value returned from System.currentTimeMillis()"...???
Is there a "better" value to use...???
Why does the calendar object need a seed value...??? I'm a vb.net developer so please excuse my ignorance in this langauge and forum..
Thanks
|
|
|
|
|
Member 2119945 wrote: Why does the calendar object need a seed value...???
It doesn't. By default, Calendar.getInstance() will return a calendar object initilised to the current date and time, using the current timezone and locale. The J2ME Calendar is a cut-down version of the J2SE class with some methods removed but it has the same default constructor.
Member 2119945 wrote: What do you mean to "check the value returned from System.currentTimeMillis()"...???
Well, the code that you have posted looks correct, there are no errors in the code. So, if there is nothing wrong with the code, the obvious next point to investigate is the value which you are using to seed the calendar. If you put the wrong value in at the start of the process, you will get the wrong value out at the end.
Is it possible that for some reason System.currentTimeMillis is returning the wrong value? Not sure why that would happen (time zones?), but I agree with Richard and that would be the next thing I check. That's not so easy to do if this is happening unpredictably, I agree.
Maybe you could search the Nokia S40 forums to see if anyone else has any issues with currentTimeMillis (S40 may not be the correct platform for this phone type - I'm not sure but you get the idea).
|
|
|
|
|
Hi David,
Are you saying that the following line is not really needed...???
ca.setTime(new Date(System.currentTimeMillis()));
If the .getInstance method returns an initialised object with the phone's current data and time, why use it at all...
Thanks
|
|
|
|
|
Most of your code is not needed, try this:
private String getTimestamp() {
try {
Calendar ca = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String stime = df.format(ca.getTime());
System.out.printf("%s\n", stime);
} catch (Exception e) {
}
return stime;
}
[edit]As David Skelly points out below, SimpleDateFormat is not available on the 2323, but there may still be a somewhat less complex method you can work on. I'm reasonably sure you do not need to use the System.currentTimeMillis() function after obtaining the Calendar object.[/edit]
It's time for a new signature.
modified on Tuesday, June 15, 2010 1:00 PM
|
|
|
|
|
Is SimpleDateFormat supported in J2ME?
|
|
|
|
|
David Skelly wrote: Is SimpleDateFormat supported in J2ME?
Looks like it according to this[^].
It's time for a new signature.
|
|
|
|
|
But according to this[^] the Nokia 2323 only supports CLDC and MIDP, not CDC, in which case SimpleDateFormat is not available.
It's a minefield. So much for WORA.
|
|
|
|
|
David Skelly wrote: So much for WORA
Always assume WOWTF!
It's time for a new signature.
|
|
|
|
|
Hi All...
Thanks for your help...
Ive had the .setTime line removed from the code and will test it..
I'm not sure why the extra lines of code were added in there.. it does seem a little convoluted way to achieve sending of a date/time value, but if it works, I'm happy...
Thanks heaps for pointing me in the right direction..
Regards
|
|
|
|
|
Hello Friends
I am using some images as background in my application.I want when I send that jar file to someone else then I dont need to send that files with jar file.So,where do I need to add my Images?In which Folder Do i need to add them so that while creation of jar file they also get bundle into it.I m using Netbeans6.7.1
I googled but not any proper anser found.
Any Ideas??
Thanks & Regards
Yogesh
|
|
|
|
|
Hey Guys
I found the solution.First Create a image folder in src folder.Then go to Project properties in Netbeans.Select Library,Add jar folder and then add that Image folder.And after that
Here is the code below:
URL myurl = Thread.currentThread().getContextClassLoader().getResource("Images/Logo.jpg");
ImageIcon im = new ImageIcon(myurl);
Anyway,thanks who viewed my Question.
Very fast starting on Monday At Work
Regards
Yogesh.
|
|
|
|
|
Hi guys,
I've got an issue here. I've created an application in Java that uses the DatagramSocket and DatagramPacket classes to send the byte array of data through the UDP protocol.
On the other hand, I'm trying to experiment using an Visual Basic application to receive the sent byte array of data.
However, I'm not sure whether if the received data is the correct one. How do I verify the data?
I'm using both the applications in windows PC, so there's is'nt a need to decode in Big Endians format.
I'm sending the byte array of data in different sizes. I've tried to output the sent data in String format in Java.
This is what I get:
eg.
byte[] data = s.getBytes();
System.out.println(data)
where s is a string variable that holds the converted byte arraydata.
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
pohcb_sonic wrote: How do I verify the data?
Well only you can answer that. You know what the data is, what format it is in, whether it is character (MBCS or Unicode) etc. So add some code at either end to check that you receive what you expect. Maybe precede each UDP packet with a length word so the receiver knows how many bytes it should receive, add a check digit at the end etc., etc.
pohcb_sonic wrote: I've tried to output the sent data in String format in Java.
This is what I get:
You showed the Java code but not the results.
It's time for a new signature.
|
|
|
|
|
The messages sent is displayed in hexadecimal format and at the same time, sent in bytes through the java application.
The code is as follows:
public void Display_Msg(int SIZE){
String S;
int DisplayLen = 0;
if (SIZE > txtSpd.getColumns()-1){
for(int i = 0; i< txtSpd.getColumns(); i++){
S = Integer.toString(ByteConversion(byteTxtMsg[i]), 16) + " ";
txtSpd.append(S);
}
txtSpd.append("\n");
for(int j = txtSpd.getColumns()-1; j< SIZE; j++){
S = Integer.toString(ByteConversion(byteTxtMsg[j]), 16) + " ";
txtSpd.append(S);
DisplayLen = txtSpd.getLineCount();
}
txtSpd.append("\n");
}
if (SIZE <= txtSpd.getColumns()-1){
for(int i = 0; i< SIZE; i++){
S = Integer.toString(ByteConversion(byteTxtMsg[i]), 16) + " ";
txtSpd.append(S);
DisplayLen = txtSpd.getLineCount();
}
txtSpd.append("\n");
}
if (DisplayLen > 18){
txtSpd.setText("");
}
String dat1="";
byte Msg[] = new byte[50];
for (int k = 0; k<SIZE; k++){
dat1 = Integer.toString(ByteConversion(byteTxtMsg[k]), 16) + " ";
}
Msg = dat1.getBytes();
try{
udpC.send(Msg);
}
catch (IOException w){
System.out.println("Error: " + w);
}
}
udpC is the instance object of the UDPConnect class involved in the declarations of DatagramPackets and DatagramSockets.
the Send method in udpC class is called.
Following is the sending portion of send method in the UDPConnect class:
public void send(byte[] data) throws IOException {
if (data.length > 8192) throw new IOException("Too much data");
DatagramPacket dp = new DatagramPacket(data, data.length, remote, port);
ds.send(dp);
}
So far, the connection and receiving portion of my application in VB has no problems. The problem now is the decoding of the message portion, whereby the decoding of the messages received seems to be different from what I've send through in the Java application.
The sending and receiving of the messages is in bytes. Could it be that sending portion of the messages in bytes in Java has something to do with this, as it is known that the bytes in Java has some restrictions?
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
modified on Monday, June 14, 2010 8:47 PM
|
|
|
|
|
pohcb_sonic wrote: Could it be that sending portion of the messages in bytes in Java has something to do with this, as it is known that the bytes in Java has some restrictions?
I'm not aware of any restrictions in this area. You say the decoding gives a different message form the sender, but if you are sending the raw bytes of the source message there should not be any need for decoding. Just ensure that the receiver understands the exact format of the data it is reading.
It's time for a new signature.
|
|
|
|
|
Hello Friends
I am adding a BackGround image to JPanel in two ways but It is not resizing according to JPanel.
First I added the Image to JLabel and then I added tht Label to Panel but after googling I found tht If we are adding through Label then only borderlayout take care of resizing and I tried all options of resizing but no use.
Then,Second I tried by creating a new class implements through JPanel.here is the code below:
class BackgroundPanel extends JPanel
{
Image image;
public BackgroundPanel()
{
try
{
image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("c:\\Logo.jpg"), "Logo.jpg"));
}
catch (Exception e) { }
}
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
if (image != null)
g.drawImage(image, 0,0,this.getWidth(),this.getHeight(),this);
}
}
With this method then i created the object like this
JPanel panel = new BackGroundPanel();
And added to ContentPane but with this method no Image is coming in background.
Any Ideas Please.
Thanks & Regards
Yogesh
|
|
|
|
|
What does this comment mean in your code above:
I don't see where you are handling this exception. If you get any sort of exception while loading the image, you just swallow it and carry on regardless.
|
|
|
|
|
Ok David,thx for ur advice.
But what abt resizing of image?
Thanks
Yogesh
|
|
|
|
|
I'm not a Swing programmer, so take this advice with a large, large pinch of salt.
Reading the documentation for Graphics, it looks as if drawImage is overloaded. The javadoc for the drawImage method you are calling says:
Draws as much of the specified image as has already been scaled to fit inside the
specified rectangle.
In other words, it does not resize the image.
There is another drawImage method that says:
Draws as much of the specified area of the specified image as is currently available,
scaling it on the fly to fit inside the specified area of the destination drawable
surface.
It sounds to me as if this is what you want.
My advice would be to read the documentation on how to draw and resize images. Sorry I can't be more help, but as I said, I am not a Swing programmer.
|
|
|
|
|
Thanks A Lot David for ur Advice.
I am also learning and learned a lot from CodeProject and still learning...
Thanks Anyway.
Regards
Yogesh
|
|
|
|