04/03/2014, 00:31
|
| | Fecha de Ingreso: julio-2010
Mensajes: 216
Antigüedad: 14 años, 5 meses Puntos: 0 | |
Respuesta: NullPointerException Hola,
Simplifico un poco el código eliminando líneas que no son importantes.
A ver si podéis echarme una mano. public class Station {
/************ Attributes ****************/
/************ Methods ****************/ private Station ()
{
} public static void main (String[] args)
{
/* Objects creation */
Station stationAtocha;
stationAtocha = new Station();
Route Route1;
Route1 = new Route(); NULLPOINTEREXCEPTION!!!!!!
Point Point1; // Declaration
Point1 = new Point(); // Creation, Instantiation
Route1.point1 = Point1; // Association
Point Point2;
Point2 = new Point();
Route1.point2 = Point2;
Route1.autoConnectPath();
}
} abstract public class Path {
/************ Attributes ****************/
protected boolean isConnected;
Point point1;
Point point2;
/************ Methods ****************/
protected Path ()
{
if ((true == point1.hasRightPosition()) && (true == point2.hasRightPosition())) NULLPOINTEREXCEPTION!!!!!!
{
isConnected = true;
}
else
{
isConnected = false;
}
}
abstract protected void autoConnectPath();
} public class Route extends Path {
/************ Attributes ****************/
public boolean Established;
/************ Methods ****************/
protected Route() NULLPOINTEREXCEPTION!!!!!!
{
Established = false;
}
protected void autoConnectPath()
{
if (false == point1.hasRightPosition())
{
point1.changePosition();
}
if (false == point2.hasRightPosition())
{
point2.changePosition();
}
this.isConnected = true;
}
public boolean establishRoute()
{
if (true == isConnected)
{
Established = true;
}
return isConnected;
}
} public class Point {
public enum pointPosition {GOOD, WRONG};
/************ Attributes ****************/
pointPosition Position;
/************ Methods ****************/
protected Point()
{
Position = pointPosition.WRONG;
}
public boolean hasRightPosition()
{
boolean isInGoodPosition = false;
if (pointPosition.GOOD == this.Position)
{
isInGoodPosition = true;
}
return isInGoodPosition;
}
protected void changePosition()
{
if (pointPosition.GOOD == this.Position)
{
this.Position = pointPosition.WRONG;
}
else
{
this.Position = pointPosition.GOOD;
}
}
} |