Java.lang.NullPointerException

edited June 2015 in Library Questions

Hi Guys,

I can't find where is this error. Can you help me???

UnfoldingMap map;
Serial portaserial; // objeto criado da classe serial.
String dadosgps = portaserial.readString();
            
 
void setup() {
  
  String portName = Serial.list()[0]; // porta no qual o arduino ira se comunicar
  portaserial = new Serial(this, portName, 9600); 
String latStr = dadosgps.substring(dadosgps.indexOf("lat:")+4, dadosgps.indexOf("lon:")-1);        
String lonStr = dadosgps.substring(dadosgps.indexOf("lon:")+4, dadosgps.length());

 
// Convert from geo-system of your GPS device to Mercator
 
float lat = Float.parseFloat(latStr);
float lon = Float.parseFloat(lonStr);
Location location = new Location(lat, lon);
            
        size(800, 600);
        map = new UnfoldingMap(this);
        MapUtils.createDefaultEventDispatcher(this, map);
        map = new UnfoldingMap(this, new Google.GoogleMapProvider());
        map.zoomAndPanTo(new Location(-31.3199163,-54.0902512), 14);
        
}
 
void draw() {
  {
       if ( portaserial.available() > 0) 
  {  
       dadosgps = portaserial.readStringUntil('\n');         
  } 
println(dadosgps); 
delay(100);
}
  
  
    map.draw();
    Location location = map.getLocation(mouseX, mouseY);
    fill(0);
    text(location.getLat() + ", " + location.getLon(), mouseX, mouseY);
    
    Location berlinLocation = new Location(-31.3252781,-54.0958781);
    Location dublinLocation = new Location(-31.315926,-54.107566);
     
// Create point markers for locations
SimplePointMarker berlinMarker = new SimplePointMarker(berlinLocation);
SimplePointMarker dublinMarker = new SimplePointMarker(dublinLocation);

// Adapt style
berlinMarker.setColor(color(255, 0, 0, 100));
berlinMarker.setStrokeColor(color(255, 0, 0));
berlinMarker.setStrokeWeight(3);
     
// Add markers to the map
map.addMarkers(berlinMarker, dublinMarker);
}





Answers

  • Indicating at which line the error happens can help us to help you... Maybe also show the full console log.

  • I'd start by looking at line 3 given that you don't initialise portaserial until line 9.

Sign In or Register to comment.