Quellcode durchsuchen

Fixes nullpointer when deleting Broker

Andreas T. Meyer-Berg vor 5 Jahren
Ursprung
Commit
d12f1825aa

+ 1 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/Controller.java

@@ -201,7 +201,7 @@ public class Controller {
 			//Skip ports that are not connected
 			if(p.getConnection()==null)continue;
 			Connection c = p.getConnection();
-			//remove from connection
+			//remove from connect
 			c.removeSmartDevice(p);
 			//remove from protocol
 			if(c.getProtocol()!=null)c.getProtocol().removeDevice(p);

+ 1 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/protocols/MQTT_protocol.java

@@ -238,7 +238,7 @@ public class MQTT_protocol implements Protocol {
 	public void removeDevice(Port device) {
 		/**
 		 * true if the device was removed
-		 */System.out.println("Halllo????");
+		 */
 		boolean removedDevice=false;
 		if (broker == device){
 			broker = null;

+ 5 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationPanel.java

@@ -165,10 +165,13 @@ public class VisualisationPanel extends JPanel {
 					if (broker!= sd) {
 						// Check if dragged object
 						int s_x, s_y, sd_x, sd_y;
-						if (broker.getOwner() == interactor.dragged) {
+						if (broker != null && broker.getOwner() == interactor.dragged) {
 							s_x = interactor.dragged_x;
 							s_y = interactor.dragged_y;
-						} else {
+						} else if(broker==null){
+							s_x=model.getWidth()/2;
+							s_y=model.getHeight()/2;
+						}else{
 							s_x = broker.getOwner().getX();
 							s_y = broker.getOwner().getY();
 						}