Sagewire Logo

how do I use String's format? not working on XP

17 Message(s) by 4 Author(s) originally posted in java language


From: Jim Michaels Date:   Friday, June 01, 2007
import JAVA.lang.String;
...
public void paint(Graphics g) {
Graphics2D comp2d = (Graphics2D)g;
Dimension appletSize = this.getSize();
appletsize_x = appletSize.width;
appletsize_y = appletSize.height;
String sx=String.format("%d", appletsize_x);
String sy=String.format("%d", appletsize_y);
g.drawString(sx, 200,30);
g.drawString(sy, 200,60);
g.setColor(Color.red);
g.fillOval(x_pos - radius, y_pos - radius, 2*radius, 2*radius);
}
...
}

ballapplet.JAVA:101: cannot resolve symbol
symbol : method format (JAVA.lang.String,int )
location: class JAVA.lang.String
String sx=String.format("%d", appletsize_x);
^
ballapplet.JAVA:102: cannot resolve symbol
symbol : method format (JAVA.lang.String,int)
location: class JAVA.lang.String
String sy=String.format("%d", appletsize_y);
^
2 errors
--

------------------------------------
Jim Michaels
for email, edit the address

RAM Disk is *not* an installation method.


From: Donkey Hot Date:   Friday, June 01, 2007
wrote in message in
qdnXeV0YZe5f3bnZ2dnUVZ_hudnZ2d@xxxxxxxxxxx:

import JAVA.lang.String;
...



It's not dependent on XP, but JAVA run time version .

1.4.2 String doesn't have format(), while JAVA 1.5 (5) and later does.

--
Alcoholics Anonymous is when you get to drink under someone else's name.


From: Jim Michaels Date:   Saturday, June 02, 2007
wrote in message:
wrote in message in
qdnXeV0YZe5f3bnZ2dnUVZ_hudnZ2d@xxxxxxxxxxx:
import JAVA.lang.String;
...
It's not dependent on XP, but JAVA runtime version.
1.4.2 String doesn't have format(), while JAVA 1.5 (5) and later does.



huh?
I justr installed the latest JAVA SDK .

--

------------------------------------
Jim Michaels
for email, edit the address

RAM Disk is *not* an installation method.


From: Jim Michaels Date:   Saturday, June 02, 2007
wrote in message:
wrote in message:
wrote in message in
qdnXeV0YZe5f3bnZ2dnUVZ_hudnZ2d@xxxxxxxxxxx:

import JAVA.lang.String;
...

It's not dependent on XP, but JAVA runtime version.

1.4.2 String doesn't have format(), while JAVA 1.5 (5) and later does.

huh?
I justr installed the latest JAVA SDK.



hmm. correction. I have 2 sdk's installed, 1.4.2 and the latest, and
the one that's in the path is 1.4.2...
so... how do I convert an int to a String in 1.4.2?

--

------------------------------------
Jim Michaels
for email, edit the address

RAM Disk is *not* an installation method.


From: Dorian Date:   Sunday, June 03, 2007
On 2007-06-02 16:20:37 -0500, Jim Michaels
<jmichae3REMOVE@xxxxxxxxxxx> said:

wrote in message:
hmm. correction. I have 2 sdk's installed, 1.4.2 and the latest, and
the one that's in the path is 1.4.2...
so... how do I convert an int to a String in 1.4.2?



How about:

int I = 22;
String s = I + "";

Bob
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----


From: Lew Date:   Sunday, June 03, 2007
wrote in message:
hmm. correction. I have 2 sdk's installed, 1.4.2 and the latest, and
the one that's in the path is 1.4.2...
so... how do I convert an int to a String in 1.4.2?



Take note:
<http://JAVA.sun.com/j2se/1.4.2/index.jsp>
J2SE 1.4.2 has begun the Sun End of Life (EOL) process.



At over five years old, 1.4.2 is getting long in the tooth. JAVA 5 is almost
three, and is not even the current version.

wrote in message:
How about:
int I = 22;
String s = I + "";



Which in turn acts as if it invokes the
<http://JAVA.sun.com/j2se/1.4.2/docs/api/JAVA/lang/Integer.html#toString()>
for an Integer version of the int, which converts that value
exactly as if the integer value were given as an argument to the toString(int) method.


<http://JAVA.sun.com/j2se/1.4.2/docs/api/JAVA/lang/Integer.html#toString(int)>
This is also how the
<http://JAVA.sun.com/j2se/1.4.2/docs/api/JAVA/lang/String.html#valueOf(int)>
method works. Any particular reason not to use one of those directly?

<http://JAVA.sun.com/docs/books/jls/third_edition/html/expressions.html#15.18.1.1>
Any type may be converted to type String by string conversion.
A value x of primitive type T is first converted to a reference value as if by giving it as an argument to an appropriate class instance creation expression:
... This reference value is then converted to type String by string conversion.
... the conversion is performed as if by an invocation of the toString method of


the referenced object with no arguments; but if the result of invoking the
toString method is null, then the string "null" is used instead.

--
Lew


From: Donkey Hot Date:   Monday, June 04, 2007
wrote in message in


wrote in message:
wrote in message:
wrote in message in
qdnXeV0YZe5f3bnZ2dnUVZ_hudnZ2d@xxxxxxxxxxx:
import JAVA.lang.String;
...
It's not dependent on XP, but JAVA runtime version.
1.4.2 String doesn't have format(), while JAVA 1.5 (5) and later does.
huh?
I justr installed the latest JAVA SDK.

hmm. correction. I have 2 sdk's installed, 1.4.2 and the latest, and
the one that's in the path is 1.4.2...
so... how do I convert an int to a String in 1.4.2?



int I = 666 ;
String s = Integer.toString(i) ;

Or remove the old SDK and use the latest.

--
Life only demands from you the strength you possess.
Only one feat is possible -- not to have run away.
-- Dag Hammarskjold


From: Jim Michaels Date:   Tuesday, June 05, 2007
wrote in message:
wrote in message:
hmm. correction. I have 2 sdk's installed, 1.4.2 and the latest, and
the one that's in the path is 1.4.2...
so... how do I convert an int to a String in 1.4.2?
Take note:
<http://JAVA.sun.com/j2se/1.4.2/index.jsp>
J2SE 1.4.2 has begun the Sun End of Life (EOL) process.
At over five years old, 1.4.2 is getting long in the tooth. JAVA 5 is
almost three, and is not even the current version.
wrote in message:
How about:

int I = 22;
String s = I + "";
Which in turn acts as if it invokes the
<http://JAVA.sun.com/j2se/1.4.2/docs/api/JAVA/lang/Integer.html#toString()>
for an Integer version of the int, which converts that value
exactly as if the integer value were given as an argument to the
toString(int) method.
<http://JAVA.sun.com/j2se/1.4.2/docs/api/JAVA/lang/Integer.html#toString(int)>
This is also how the
<http://JAVA.sun.com/j2se/1.4.2/docs/api/JAVA/lang/String.html#valueOf(int)>
method works. Any particular reason not to use one of those directly?



already tried this. my JAVA must be busted.import JAVA.lang.String;

class doit {
public static void main(String args[]) {
int i=1;
String s=i.toString();
}
}C:\prj\JAVA\swing>JAVAc str.JAVA
str.JAVA:6: int cannot be dereferenced
String s=i.toString();
^
----------------------------------------

import JAVA.lang.String;

class str {
public static void main(String args[]) {
int i=1;
Integer i1=new Integer(i);
String s=i1.toString();
}
}C:\prj\JAVA\swing>JAVA str
Exception in thread "main" JAVA.lang.NoClassDefFoundError: str

<http://JAVA.sun.com/docs/books/jls/third_edition/html/expressions.html#15.18.1.1>
Any type may be converted to type String by string conversion.
A value x of primitive type T is first converted to a reference value
as if by giving it as an argument to an appropriate class instance
creation expression:
... This reference value is then converted to type String by string
conversion.
... the conversion is performed as if by an invocation of the
toString method of
the referenced object with no arguments; but if the result of invoking
the toString method is null, then the string "null" is used instead.
--



------------------------------------
Jim Michaels
for email, edit the address

RAM Disk is *not* an installation method.


From: Donkey Hot Date:   Wednesday, June 06, 2007
wrote in message in


wrote in message:
wrote in message:
hmm. correction. I have 2 sdk's installed, 1.4.2 and the latest,
and the one that's in the path is 1.4.2...
so... how do I convert an int to a String in 1.4.2?

Take note:
<http://JAVA.sun.com/j2se/1.4.2/index.jsp>
J2SE 1.4.2 has begun the Sun End of Life (EOL) process.

At over five years old, 1.4.2 is getting long in the tooth. JAVA 5
is almost three, and is not even the current version.

wrote in message:
How about:
int I = 22;
String s = I + "";

Which in turn acts as if it invokes the
<http://JAVA.sun.com/j2se/1.4.2/docs/api/JAVA/lang/Integer.html#toStri
ng()>
for an Integer version of the int, which converts that value
exactly as if the integer value were given as an argument to the
toString(int) method.
<http://JAVA.sun.com/j2se/1.4.2/docs/api/JAVA/lang/Integer.html#toStri
ng(int)>


This is also how the
<http://JAVA.sun.com/j2se/1.4.2/docs/api/JAVA/lang/String.html#valueOf
(int)>


method works. Any particular reason not to use one of those
directly?

already tried this. my JAVA must be busted.
import JAVA.lang.String;
class doit {
public static void main(String args[]) {
int i=1;
String s=i.toString();
}
}



int isn't a class, and it has no method toString()

You can use the static method Integer.toString(i) to get a string from
int.

----------------------------------------
import JAVA.lang.String;
class str {
public static void main(String args[]) {
int i=1;
Integer i1=new Integer(i);
String s=i1.toString();
}
}



There is no need to create an Integer object just to call it's toString
(), as toString() is static, it can be called by Integer.toString(int)

C:\prj\JAVA\swing>JAVA str
Exception in thread "main" JAVA.lang.NoClassDefFoundError: str



But then, no idea why that doesn't work... I tried it in 1.4.2 JRE and
it worked fine.


From: Lew Date:   Wednesday, June 06, 2007
wrote in message in
already tried this. my JAVA [sic] must be busted.



Your JAVA is fine. You need to review the difference between primitive types
and object types, though.

import JAVA.lang.String;

class doit {
public static void main(String args[]) {
int i=1;
String s=i.toString();
}
}

wrote in message:
int isn't a class, and it has no method toString()
You can use the static method Integer.toString(i) to get a string from
int.



or String x = String.valueOf( I );

----------------------------------------
import JAVA.lang.String;

class str {
public static void main(String args[]) {
int i=1;
Integer i1=new Integer(i);
String s=i1.toString();
}
}
C:\prj\JAVA\swing>JAVA str
Exception in thread "main" JAVA.lang.NoClassDefFoundError: str

wrote in message:
But then, no idea why that doesn't work... I tried it in 1.4.2 JRE and
it worked fine.



The OP didn't compile the class first.

--
Lew

P.S., Donkey Hot, eh? Keep tilting at those windmills!


From: Lew Date:   Wednesday, June 06, 2007
wrote in message in
already tried this. my JAVA [sic] must be busted.

import JAVA.lang.String;



You do not need to import JAVA.lang.

--
Lew


From: Jim Michaels Date:   Thursday, June 07, 2007
wrote in message:
wrote in message in
already tried this. my JAVA [sic] must be busted.
Your JAVA is fine. You need to review the difference between primitive
types and object types, though.
import JAVA.lang.String;
class doit {
public static void main(String args[]) {
int i=1;
String s=i.toString();
}
}
wrote in message:
int isn't a class, and it has no method toString()

You can use the static method Integer.toString(i) to get a string from
int.
or String x = String.valueOf( I );
----------------------------------------
import JAVA.lang.String;
class str {
public static void main(String args[]) {
int i=1;
Integer i1=new Integer(i);
String s=i1.toString();
}
}
C:\prj\JAVA\swing>JAVA str
Exception in thread "main" JAVA.lang.NoClassDefFoundError: str
wrote in message:
But then, no idea why that doesn't work... I tried it in 1.4.2 JRE
and it worked fine.
The OP didn't compile the class first.



how's that? I'm the OP. please be more specific in your reply. I
do not know what you're talking about. I'm still kind of a JAVA
beginner. I thought I *did* compile the class. I ended up with a
str.class file . I did
JAVAc str.JAVA

C:\prj\JAVA\swing>dir
Volume in drive C is wdc160
Volume Serial Number is ACB2-51DD

Directory of C:\prj\JAVA\swing

06/05/2007 02:44 PM <DIR> .
06/05/2007 02:44 PM <DIR> ..
06/05/2007 02:42 PM 363 str.class
06/05/2007 02:42 PM 184 str.JAVA
------------------------------------
Jim Michaels
for email, edit the address

RAM Disk is *not* an installation method.


From: Jim Michaels Date:   Thursday, June 07, 2007
wrote in message:
wrote in message:
wrote in message in
already tried this. my JAVA [sic] must be busted.

Your JAVA is fine. You need to review the difference between
primitive types and object types, though.

import JAVA.lang.String;

class doit {
public static void main(String args[]) {
int i=1;
String s=i.toString();
}
}

wrote in message:
int isn't a class, and it has no method toString()
You can use the static method Integer.toString(i) to get a string
from int.

or String x = String.valueOf( I );

----------------------------------------
import JAVA.lang.String;

class str {
public static void main(String args[]) {
int i=1;
Integer i1=new Integer(i);
String s=i1.toString();
}
}
C:\prj\JAVA\swing>JAVA str
Exception in thread "main" JAVA.lang.NoClassDefFoundError: str

wrote in message:
But then, no idea why that doesn't work... I tried it in 1.4.2 JRE
and it worked fine.

The OP didn't compile the class first.

how's that? I'm the OP. please be more specific in your reply. I
do not know what you're talking about. I'm still kind of a JAVA
beginner. I thought I *did* compile the class. I ended up with a
str.class file. I did
JAVAc str.JAVA
C:\prj\JAVA\swing>dir
Volume in drive C is wdc160
Volume Serial Number is ACB2-51DD
Directory of C:\prj\JAVA\swing
06/05/2007 02:44 PM <DIR> .
06/05/2007 02:44 PM <DIR> ..
06/05/2007 02:42 PM 363 str.class
06/05/2007 02:42 PM 184 str.JAVA
------------------------------------
Jim Michaels
for email, edit the address
RAM Disk is *not* an installation method.



solution is classpath doesn't include .; in front, as per
http://forum.JAVA.sun.com/thread.jspa?threadID=571464
It used to be the classpath had to be set for things to work, and you
had to include the library path along with it. I do not know how true
this is anymore, or if it's only the case on a UNIX box.
I'm on XP.--

------------------------------------
Jim Michaels
for email, edit the address

RAM Disk is *not* an installation method.


From: Lew Date:   Thursday, June 07, 2007
wrote in message:
already tried this. my JAVA [sic] must be busted.

wrote in message:
The OP didn't compile the class first.

wrote in message:
how's that? I'm the OP. please be more specific in your reply. I
do not know what you're talking about. I'm still kind of a JAVA



I was confused by the fact that you showed the JAVAc command for your first
example but the JAVA command for your second.

solution is classpath doesn't include .; in front, as per
http://forum.JAVA.sun.com/thread.jspa?threadID=571464



And per the advice in your other thread in this forum.

It used to be the classpath had to be set for things to work, and you
had to include the library path along with it. I do not know how true
this is anymore, or if it's only the case on a UNIX box.
I'm on XP.



See my advice on the other thread about CLASSPATH versus the "-cp" option to JAVA.

Bear in mind that absent any overriding setting, CLASSPATH defaults to ",".

Also that you should stop using the default package once you get the hang of
things.

--
Lew


From: Jim Michaels Date:   Friday, June 08, 2007
wrote in message:
wrote in message:
already tried this. my JAVA [sic] must be busted.
wrote in message:
The OP didn't compile the class first.
wrote in message:
how's that? I'm the OP. please be more specific in your reply. I
do not know what you're talking about. I'm still kind of a JAVA
I was confused by the fact that you showed the JAVAc command for your
first example but the JAVA command for your second.
solution is classpath doesn't include .; in front, as per
http://forum.JAVA.sun.com/thread.jspa?threadID=571464
And per the advice in your other thread in this forum.
It used to be the classpath had to be set for things to work, and you
had to include the library path along with it. I do not know how true
this is anymore, or if it's only the case on a UNIX box.
I'm on XP.
See my advice on the other thread about CLASSPATH versus the "-cp"
option to JAVA.
Bear in mind that absent any overriding setting, CLASSPATH defaults to ",".
Also that you should stop using the default package once you get the
hang of things.


what is a "default package"?

--

------------------------------------
Jim Michaels
for email, edit the address

RAM Disk is *not* an installation method.


From: Jim Michaels Date:   Friday, June 08, 2007
wrote in message:
wrote in message:
already tried this. my JAVA [sic] must be busted.
wrote in message:
The OP didn't compile the class first.
wrote in message:
how's that? I'm the OP. please be more specific in your reply. I
do not know what you're talking about. I'm still kind of a JAVA
I was confused by the fact that you showed the JAVAc command for your
first example but the JAVA command for your second.
solution is classpath doesn't include .; in front, as per
http://forum.JAVA.sun.com/thread.jspa?threadID=571464
And per the advice in your other thread in this forum.
It used to be the classpath had to be set for things to work, and you
had to include the library path along with it. I do not know how true
this is anymore, or if it's only the case on a UNIX box.
I'm on XP.
See my advice on the other thread about CLASSPATH versus the "-cp"
option to JAVA.
Bear in mind that absent any overriding setting, CLASSPATH defaults to ",".
Also that you should stop using the default package once you get the
hang of things.


so it's as simple as inserting
package swingdemo;
at the top of the program and that's it? I am not understanding this
core JAVA book really well. it gives no examples and it does not really
explain itself.

--

------------------------------------
Jim Michaels
for email, edit the address

RAM Disk is *not* an installation method.


From: Lew Date:   Saturday, June 09, 2007
wrote in message:
Also that you should stop using the default package once you get the
hang of things.



wrote in message:
what is a "default package"?



Only one of the most basic concepts in JAVA - it means there is no package for
the class.

wrote in message:
so it's as simple as inserting
package swingdemo;
at the top of the program and that's it? I am not understanding this
core JAVA [sic] book really well. it gives no examples and it does not really
explain itself.



I'm afraid it's not that simple. On a file system, which is what most of us
use for our class files most of the time, the directory structure must match
the package hierarchy, rooted at an element of the class path.

Rephrased, that means if your class path includes the current working
directory (cwd, or "."), and the package (which is supposed to be based on
your Internet domain) is com.jimmichaels.swingdemo, then relative to your cwd
the class file must be in the directory "com/jimmichaels/swingdemo".

Have you even tried to read the tutorials from Sun? They might be a better
place to start than /Core JAVA/ for you. (It's not "core JAVA" - case matters
in this world.)
<http://JAVA.sun.com/docs/books/tutorial/reallybigindex.html>

Also, GIYF. If you see a term you do not recognize, how about looking it up,
hm? UseNet helps those who help themselves.

--
Lew



Next Message: JAVA soap client


Blogs related to how do I use String's format? not working on XP

Customizing pages (updated)
The displayName attribute lets specify a label that is different from the "un-camelcased" property name, while the format attribute lets us specify any format string that the Java format objects can understand. ...

OpenDS 0.9.0-build001 is now available
Even though some forms of the backups do use zip format, others (eg, when encryption is enable) do not. Revision 1890 (Issues #1479, 1587, 1606) -- Update the access control processing code so that operational attributes do not get ...

Google Developers day
The Google Web Toolkit (GWT) is an open source Java-centric framework for creating AJAX applications. GWT cross-compiles Java source into JavaScript, allowing Java developers to use their existing Java skills and tools to easily create ...

CRIS PAGE (created)
Bug, SCRP-10, Column sorting, row highlighting sometimes not working, Bob Swift, Closed. Improvement, SCRP-9, Allow control of sql data output format, Bob Swift, Closed. Bug, SCRP-8, Files from home folder not found, Bob Swift, Closed ...

Re: searching a date range
Hi you know, actually we dont indexed this field as Date. we always use string instead of Date type because we use both Hijri date and Gregorian date so if we put a Hijri date the DateField not work properly. that is why we index such ...

svn commit: r539578 - in /maven/plugins/trunk/maven-eclipse-plugin ...
+ * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional