Loading...
Logo
Processing Forum
This post becames outdated please read this instead


This sketch runs fine, but suddenly, it freezes throwing this error:

java.lang.NullPointerException

at processing.core.PGraphics.image(PGraphics.java:2829)

at de.fhpotsdam.unfolding.mapdisplay.ProcessingMapDisplay.draw(Unknown Source)

at de.fhpotsdam.unfolding.UnfoldingMap.draw(Unknown Source)

at studying_stream_05E.draw(studying_stream_05E.java:145)

at processing.core.PApplet.handleDraw(PApplet.java:1631)

at processing.core.PApplet.run(PApplet.java:1530)

at java.lang.Thread.run(Thread.java:680)

The offscreen renderer has already been set. Maybe you are calling beginDraw() again before endDraw()?

 
I think it happens when zooming and panning around, but not sure. With default provider i haven't seen this. It  

It happens with default provider Also . I think, it is related to threads after all. BUt i don't know how to handle this. SEE MINE REPLY

Do you think it is related to the provider? Is there a way to avoid this error to stops the sketch? I tried a basic try/catch but is freezing anyway. When error occurs the highlighted line is map.draw();

I isolated the unfolding code to paste it below. The happens erratically... If i find any thing new i'll post here again.

Copy code
  1. import processing.opengl.*;

  2.   /// unfolding imports
  3. import codeanticode.glgraphics.*;
  4. import de.fhpotsdam.unfolding.*;
  5. import de.fhpotsdam.unfolding.geo.*;
  6. import de.fhpotsdam.unfolding.utils.*;
  7. import de.fhpotsdam.unfolding.providers.OpenStreetMap;



  8. /// Map
  9. de.fhpotsdam.unfolding.UnfoldingMap map;


  10. void setup() {
  11.   size(1400, 800, GLConstants.GLGRAPHICS);
  12.   smooth();  
  13.   map = new UnfoldingMap(this, new OpenStreetMap.CloudmadeProvider("my key here...", 67367));
  14.   map.zoomToLevel(2);
  15.   MapUtils.createDefaultEventDispatcher(this, map);  
  16. }

  17. void draw() {

  18.   try
  19.   {
  20.     map.draw();
  21.   }catch (Exception e)
  22.   {
  23.     e.printStackTrace();
  24.   }
  25. }/// eof draw

EDIT: it seems to be not related to panning and zoom. Maybe some thread related  issue? I'm using twitter listener which is a separated thread. ??

Replies(1)

I'm posting the full code, with twitter stuff, as i think the problem migth be related. The thing is a tweeter key is needed to run the code. This is the code that gives the error. It gets tweets with geo location and plots it ti he map. It runs fine and suddenly stops with the mentioned error. 



Copy code
  1. import org.json.*;

  2. import processing.opengl.*;

  3. /// unfolding imports
  4. import codeanticode.glgraphics.*;
  5. import de.fhpotsdam.unfolding.*;
  6. import de.fhpotsdam.unfolding.geo.*;
  7. import de.fhpotsdam.unfolding.utils.*;
  8. import de.fhpotsdam.unfolding.providers.Microsoft;
  9. import de.fhpotsdam.unfolding.providers.OpenStreetMap;
  10. import de.fhpotsdam.unfolding.providers.Yahoo;


  11. /// Map
  12. de.fhpotsdam.unfolding.UnfoldingMap map;
  13. TwitterStream twitter;
  14. FilterQuery query;



  15. PFont font;
  16. double[][] boundingBox= {
  17.   {
  18.     -180, -90
  19.   }
  20.   , {
  21.     180, 90
  22.   }
  23. }; /// whole world;
  24. float[] seno = new float[360];
  25. float[] coseno = new float[360];


  26. ArrayList<TweetContainer> happy = new ArrayList<TweetContainer>();




  27. void setup() {
  28.   size(1400, 800, GLConstants.GLGRAPHICS);
  29.   smooth();
  30.   font = createFont("Helvetica-bold", 48);

  31.   ////unfolding map stuff
  32.   // map = new UnfoldingMap(this, new OpenStreetMap.CloudmadeProvider("key here", 67367));
  33.   map = new UnfoldingMap(this);
  34.   map.zoomToLevel(2);
  35.   MapUtils.createDefaultEventDispatcher(this, map);



  36.   //// twitter4j stuff

  37.   //// credentials
  38.   ConfigurationBuilder cb = new ConfigurationBuilder();
  39.   cb.setOAuthConsumerKey("keys here");
  40.   cb.setOAuthConsumerSecret("keys here");
  41.   cb.setOAuthAccessToken("keys here");
  42.   cb.setOAuthAccessTokenSecret("keys here");
  43.   cb.setDebugEnabled(true);


  44.   

  45.   TwitterStream twitter = new TwitterStreamFactory(cb.build()).getInstance();
  46.   FilterQuery filtro = new FilterQuery();
  47.   filtro.locations(boundingBox);
  48.   twitter.addListener(listener);
  49.   twitter.filter(filtro);

  50.   for (int i = 0; i < seno.length; i++)
  51.   {
  52.     seno[i] = sin(radians(i));
  53.     coseno[i] = cos(radians(i));
  54.   }
  55. }

  56. void draw() {

  57.   map.draw();


  58.   fill(0, 120);
  59.   noStroke();
  60.   rect(0, 0, 200, height);
  61.   rect(width - 200, 0, width, height);
  62.   color hapC = color (255, 200, 50);
  63.   color sadC = color (255, 50, 200);

  64.   for (int i = 0 ; i < happy.size(); i++)
  65.   {
  66.     if (happy.size() > 0)
  67.     {
  68.       fill(hapC);
  69.       happy.get(i).displayGeo(hapC);
  70.     }
  71.   }
  72. }/// eof draw



  73. ////////***************************** TWETTER STATUS LISTNER ****************************///////

  74. StatusListener listener = new StatusListener() {

  75.   public void onStatus(Status status) {

  76.     if (status.getGeoLocation() != null)
  77.     {
  78.       if (status.getText().contains(":)")) 
  79.       {  
  80.         happy.add(new TweetContainer(status, 10));
  81.         return;
  82.       }
  83.     }
  84.   }

  85.   public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
  86.     //System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
  87.   }
  88.   public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
  89.     //System.out.print("!!!!!!!!!!!-Got track limitation notice:" + numberOfLimitedStatuses);
  90.     //println("  running for "+ ((millis()-initialTime)/1000) + " seconds");
  91.   }
  92.   public void onScrubGeo(long userId, long upToStatusId) {
  93.     //System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
  94.   }

  95.   public void onException(Exception ex) {
  96.     ex.printStackTrace();
  97.   }
  98. };





  99. /////////////************** CLASS TWEET CONTAINER ***************///////




  100. class TweetContainer
  101. {  
  102.   ///......///...... variables holding tw data
  103.   String who = "";
  104.   String time = "";
  105.   String txt = "";
  106.   String where = "";
  107.   double lat = 0.0;
  108.   double lon = 0.0;
  109.   String imgUrl;
  110.   PImage img;
  111.   float life = 255f;
  112.   float xp;
  113.   float yp ;
  114.   int iterator = 0;
  115.   float pos;

  116.   TweetContainer(Status s, float _pos)
  117.   {
  118.     pos = _pos;
  119.     who = s.getUser().getScreenName();
  120.     time = s.getCreatedAt().toString();
  121.     txt = s.getText();
  122.     GeoLocation g = s.getGeoLocation();
  123.     if (g!=null)
  124.     {
  125.       where = g.toString();     
  126.       lat = g.getLatitude();
  127.       lon = g.getLongitude();
  128.       where  = nf( (float)lon, 3, 10)+ " " + nf( (float)lat, 3, 10);
  129.       String imgUrl = s.getUser().getProfileImageURL().toString();
  130.       if (imgUrl.startsWith("//")) {
  131.         println("s3 weirdness");
  132.         imgUrl = "http:" + imgUrl;
  133.       }

  134.       img = loadImage(imgUrl, "jpeg");
  135.       //println(imgUrl);
  136.     }
  137.   }   
  138.  

  139.   void displayGeo(color c)
  140.   {     
  141.     de.fhpotsdam.unfolding.geo.Location loc = new de.fhpotsdam.unfolding.geo.Location(lat, lon);
  142.     PVector vec = map.getScreenPosition(loc);
  143.     fill(255, 80, 30, 120);
  144.     noStroke();
  145.     iterator = (iterator + 5)%seno.length-1;
  146.     int iterator2 = (180+iterator + 5)%seno.length-1;
  147.     ellipse(vec.x + coseno[iterator]*2, vec.y + seno[iterator]*2, 4, 4);
  148.     ellipse(vec.x + coseno[iterator2]*2, vec.y + seno[iterator2]*2, 4, 4);
  149.     noFill();
  150.     stroke(0, 80);
  151.     ellipse(vec.x, vec.y, 10, 10);
  152.   }
  153. }//.....eofTweetContainer