Dies ist eine statische Kopie unseres alten Forums. Es sind keine Interaktionen möglich.
This is a static copy of our old forum. Interactions are not possible.

Teklan

Erfahrener Schreiberling

  • "Teklan" started this thread

Posts: 267

Date of registration: Nov 13th 2004

Location: Hannover

1

Monday, June 13th 2005, 9:57pm

Formatter.format prob

...: cannot find symbol
symbol: method format(double)
location: class java.util.Formatter
Formatter.format ( exp(x))

Ich weiß nicht woran das liegt, dass der Compiler format nicht finden kann.
Ich habe doch schon oben "import java.util*" stehen 8o.

Kann mir einer helfen? danke

The-Holy-One

Praktikant

  • "The-Holy-One" is male

Posts: 22

Date of registration: Oct 11th 2004

2

Monday, June 13th 2005, 10:03pm

Ich weiß nicht ob du den Punkt hinter util hier einfach nur vergessen hast, aber es heißt:
import java.util.*;

Ansonsten hast du es genau so geschrieben?
Formatter formatter = new Formatter(System.out, Locale.GERMANY);

This post has been edited 2 times, last edit by "The-Holy-One" (Jun 13th 2005, 10:06pm)


Teklan

Erfahrener Schreiberling

  • "Teklan" started this thread

Posts: 267

Date of registration: Nov 13th 2004

Location: Hannover

3

Monday, June 13th 2005, 10:17pm

Locale locale = Locale.GERMANY;
Formatter formatter = new Formatter(System.out, locale);

müsste auch klappen

thommyslaw

Junior Schreiberling

  • "thommyslaw" is male

Posts: 226

Date of registration: Oct 7th 2003

4

Monday, June 13th 2005, 10:36pm

versuch mal formatter.format("%...

Teklan

Erfahrener Schreiberling

  • "Teklan" started this thread

Posts: 267

Date of registration: Nov 13th 2004

Location: Hannover

5

Monday, June 13th 2005, 10:39pm

nee, funktioniert dann auch nicht. Kann es sein, dass ich Java irgendwie "unvollständig" installiert habe und ich die "format".methode wirklich nicht habe? Kann das passieren?

  • "Joachim" is male

Posts: 2,863

Date of registration: Dec 11th 2001

Location: Hämelerwald

Occupation: Wissenschaftlicher Mitarbeiter (Forschungszentrum L3S, TU Braunschweig)

6

Monday, June 13th 2005, 10:41pm

Quoted

Original von Teklan
nee, funktioniert dann auch nicht. Kann es sein, dass ich Java irgendwie "unvollständig" installiert habe und ich die "format".methode wirklich nicht habe? Kann das passieren?
Kann ich mir eigentlich nicht vorstellen.

Schreib doch mal ein *minimales* Java-Programm (also nur main-Methode), das die von Dir beschriebenen Fehler verursacht und poste es hier.
The purpose of computing is insight, not numbers.
Richard Hamming, 1962

This post has been edited 2 times, last edit by "Joachim" (Jun 13th 2005, 10:42pm)


Dude

Junior Schreiberling

Posts: 181

Date of registration: Oct 11th 2004

7

Monday, June 13th 2005, 10:45pm

Man soll ja eigentlich nicht mit Halbwissen um sich schmeissen, aber ich würd sagen, er kann das Paket nicht richtig importieren. Hatte ich die Tage auch nachdem ich das SDK neu installiert hatte. Nachdem ich auch den Java Editor neu installiert hatte, gings fehlerfrei ... vielleicht mal probieren.

Teklan

Erfahrener Schreiberling

  • "Teklan" started this thread

Posts: 267

Date of registration: Nov 13th 2004

Location: Hannover

8

Monday, June 13th 2005, 10:47pm

Hier erstmal das minimale Programm --> erzeugt den selben Fehler


import java.util.*;
import static java.lang.Math.*;

/*
* Iterativ Definition of test
*/

public class test
extends Object {

public static void main(String arg[]) {
Locale locale = Locale.GERMANY;
Formatter formatter = new Formatter(System.out, locale);
formatter.format( exp(5) );
}
}

...................................

@Dude: ok, werd ich mal versuchen

Dude

Junior Schreiberling

Posts: 181

Date of registration: Oct 11th 2004

9

Monday, June 13th 2005, 10:51pm

Uh, sollte mir den ganzen Kram durchlesen, bevor ich was poste.

Quoted

...: cannot find symbol
symbol: method format(double)
location: class java.util.Formatter
Formatter.format ( exp(x))


So kannst du formatter.format nicht aufrufen. Der erste Parameter ist quasi die Art der Ausgabe, der zweite Parameter das Auszugebene.

Also in deinem Fall:
Formatter.format("%1.2f", exp(x));

  • "Joachim" is male

Posts: 2,863

Date of registration: Dec 11th 2001

Location: Hämelerwald

Occupation: Wissenschaftlicher Mitarbeiter (Forschungszentrum L3S, TU Braunschweig)

10

Monday, June 13th 2005, 10:53pm

Quoted

Original von Teklan
import java.util.*;
import static java.lang.Math.*;
formatter.format( exp(5) );
Das ist kein Wunder, die Methode format kann mit einem double-Wert als Parameter auch nichts anfangen. Siehe API-Doc.
The purpose of computing is insight, not numbers.
Richard Hamming, 1962

  • "Joachim" is male

Posts: 2,863

Date of registration: Dec 11th 2001

Location: Hämelerwald

Occupation: Wissenschaftlicher Mitarbeiter (Forschungszentrum L3S, TU Braunschweig)

11

Monday, June 13th 2005, 10:56pm

Quoted

Original von Dude
Formatter.format("%1.2f", exp(x));
Du meinst formatter.format(...). :)
The purpose of computing is insight, not numbers.
Richard Hamming, 1962

thommyslaw

Junior Schreiberling

  • "thommyslaw" is male

Posts: 226

Date of registration: Oct 7th 2003

12

Monday, June 13th 2005, 10:57pm

na da hab ich doch wenigstens auch etwas zur lösung beigetragen ;)

Teklan

Erfahrener Schreiberling

  • "Teklan" started this thread

Posts: 267

Date of registration: Nov 13th 2004

Location: Hannover

13

Monday, June 13th 2005, 10:57pm

hmm, das minimal Programm läuft jetzt, aber bei großen gibts jetzt das da...

ConsoleIODemo.java:78: non-static method format(java.lang.String,java.lang.Object...) cannot be referenced from a static context
Formatter.format("%1.2f", exp(x));

Dude

Junior Schreiberling

Posts: 181

Date of registration: Oct 11th 2004

14

Monday, June 13th 2005, 10:58pm

Wenn mans ganz genau nimmt, meine ich:
formatter.format("%1.2f", Math.exp(x));

Allerdings habe ich mich an dem Zitat orientiert, nicht die intelligenteste Vorgehensweise, hehe.

Dude

Junior Schreiberling

Posts: 181

Date of registration: Oct 11th 2004

15

Monday, June 13th 2005, 11:00pm

Quoted

Original von Teklan
hmm, das minimal Programm läuft jetzt, aber bei großen gibts jetzt das da...

ConsoleIODemo.java:78: non-static method format(java.lang.String,java.lang.Object...) cannot be referenced from a static context
Formatter.format("%1.2f", exp(x));


Spontan ... versucht du die Ausgabe in einer zusätzlichen, statischen Methode unterzubringen? Wenn ja, brauchst nicht, geht auch in der Main-Methode. Wenn nein, Beitrag ignorieren ;)

  • "Joachim" is male

Posts: 2,863

Date of registration: Dec 11th 2001

Location: Hämelerwald

Occupation: Wissenschaftlicher Mitarbeiter (Forschungszentrum L3S, TU Braunschweig)

16

Monday, June 13th 2005, 11:07pm

Quoted

Original von Teklan
hmm, das minimal Programm läuft jetzt, aber bei großen gibts jetzt das da...

ConsoleIODemo.java:78: non-static method format(java.lang.String,java.lang.Object...) cannot be referenced from a static context
Formatter.format("%1.2f", exp(x));
Hättest Du in die API-Doc geschaut, wüßtest Du, daß die Klasse Formatter keine statische Methode format besitzt, die Du hier aufzurufen versuchst.
The purpose of computing is insight, not numbers.
Richard Hamming, 1962

Teklan

Erfahrener Schreiberling

  • "Teklan" started this thread

Posts: 267

Date of registration: Nov 13th 2004

Location: Hannover

17

Monday, June 13th 2005, 11:11pm

Das ding ist nur, dass ich keine zusätzliche static methode habe, ausser der main. Ansonsten habe ich auch keine anderen Variablen, die statisch sind. An der for-schleife liegts auch nicht - ich prüf momentan weiter...

Teklan

Erfahrener Schreiberling

  • "Teklan" started this thread

Posts: 267

Date of registration: Nov 13th 2004

Location: Hannover

18

Monday, June 13th 2005, 11:16pm

Liegts vllt doch an der for-schleife? Wird hier irgend etwas statisches erzeugt? a,b,h sind initalisiert.


for ( double x = a; x < b; x = x + h) {
Formatter.format("%1.2f", exp(x));
}

  • "Joachim" is male

Posts: 2,863

Date of registration: Dec 11th 2001

Location: Hämelerwald

Occupation: Wissenschaftlicher Mitarbeiter (Forschungszentrum L3S, TU Braunschweig)

19

Monday, June 13th 2005, 11:17pm

Quoted

Original von Teklan
Liegts vllt doch an der for-schleife? Wird hier irgend etwas statisches erzeugt? a,b,h sind initalisiert.


for ( double x = a; x < b; x = x + h) {
Formatter.format("%1.2f", exp(x));
}
Du kennst den Unterschied zwischen
Formatter.format(...)
und
(new Formatter(...)).format(...)?

Lies nochmal meinen letzten Beitrag.
The purpose of computing is insight, not numbers.
Richard Hamming, 1962

This post has been edited 1 times, last edit by "Joachim" (Jun 13th 2005, 11:18pm)


Teklan

Erfahrener Schreiberling

  • "Teklan" started this thread

Posts: 267

Date of registration: Nov 13th 2004

Location: Hannover

20

Monday, June 13th 2005, 11:41pm

mensch, das war ne schwere Geburt. Jetzt klappt es, danke für eure ganzen Posts