Jeg er helt ny til alt det her med Java, kan næsten ingenting og selv kun det mest basale.
Siden jeg lærer ud er gammel, men fandt et andet sted hvor den blev anbefalet.
Jeg har fundet følgende
her!
import java.awt.*; // Point-klassen skal importeres fra pakken java.awt
public class Punkt
{
public static void main(String[] args)
{
Point p;
p = new Point();
int a;
a = p.x;
System.out.println("a: "+a);
System.out.println("x-koordinat: "+p.x);
System.out.println("y-koordinat: "+p.y);
p.x = 110;
p.y = 210;
System.out.println("x-koordinat: "+p.x);
System.out.println("y-koordinat: "+p.y);
p.move(200,300);
System.out.println("x-koordinat: "+p.x);
System.out.println("y-koordinat: "+p.y);
p.x = p.x + 5;
System.out.println("x-koordinat: "+p.x);
System.out.println("y-koordinat: "+p.y);
p.translate(-10,20);
System.out.println("x-koordinat: "+p.x);
System.out.println("y-koordinat: "+p.y);
}
}
Når jeg kopiere koden ind i Eclipse, og kører programmet, burde jeg få følgende:
a: 0
x-koordinat: 0
y-koordinat: 0
x-koordinat: 110
y-koordinat: 210
x-koordinat: 200
y-koordinat: 300
x-koordinat: 205
y-koordinat: 300
x-koordinat: 195
y-koordinat: 320
Men jeg får denne:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
p.x cannot be resolved or is not a field
p.x cannot be resolved or is not a field
p.y cannot be resolved or is not a field
p.x cannot be resolved or is not a field
p.y cannot be resolved or is not a field
p.x cannot be resolved or is not a field
p.y cannot be resolved or is not a field
The method move(int, int) is undefined for the type Point
p.x cannot be resolved or is not a field
p.y cannot be resolved or is not a field
p.x cannot be resolved or is not a field
p.x cannot be resolved or is not a field
p.x cannot be resolved or is not a field
p.y cannot be resolved or is not a field
The method translate(int, int) is undefined for the type Point
p.x cannot be resolved or is not a field
p.y cannot be resolved or is not a field
at Punkt.main(Punkt.java:11)
Kort fortalt forekommer fejlen alle de steder hvor p.x og p.y optræder..
Jeg håber nogle vil tage sig tid til at hjælpe..
Indlæg senest redigeret d. 03.03.2009 16:25 af Bruger #13920