顯示具有 Processing 標籤的文章。 顯示所有文章
顯示具有 Processing 標籤的文章。 顯示所有文章

2014/10/21

Processing loadJSONArray() 問題

 在 Processing 中要載入一個 json 檔中存放的 array 資料會參考官方網站中以下列的程式碼執行:

JSONArray values;

void setup() {
  try {
    // values = new JSONArray();
    values = loadJSONArray("data.json");
  } catch(Exception e) {
    print(e.getMessage());
  }
  if (values == null) {
    println("values is null");
    exit();
  }
  for (int i = 0; i < values.size(); i++) {   
    JSONObject animal = values.getJSONObject(i);
    int id = animal.getInt("id");
    String species = animal.getString("species");
    String name = animal.getString("name");
    println(id + ", " + species + ", " + name);
  }
}

但一執行會遇到 cannot convert from JSONArray to JSONArray 的奇怪錯誤訊息,如果你在Eclipse 中開發很快就會發現問題在那裡。若是第一次接觸Processing 的人,真的是會被搞死。只要把第一行 JSONArray values;
前面加上 processing.data. 即可。

2014/09/23

Processing 錯誤訊息原因

  最近在學 Processing 2,有一次因為到選單 File > Preferenece調整了記憶使用量造成以下錯誤訊息及程式掛在那裡不動,若沒真的很懂 Increase maximum available memory 這項設定,不要亂勾:
 


Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: GC overhead limit exceeded
at processing.opengl.PGraphicsOpenGL$InGeometry.allocate(PGraphicsOpenGL.java:7164)
at processing.opengl.PGraphicsOpenGL$InGeometry.(PGraphicsOpenGL.java:7136)
at processing.opengl.PGraphicsOpenGL.newInGeometry(PGraphicsOpenGL.java:6855)
at processing.opengl.PShapeOpenGL.(PShapeOpenGL.java:325)
at processing.opengl.PGraphics3D.createShapeImpl(PGraphics3D.java:258)
at processing.opengl.PGraphics3D.createShape(PGraphics3D.java:181)
at processing.core.PApplet.createShape(PApplet.java:11689)
at CubicGridRetained.setup(CubicGridRetained.java:48)
at processing.core.PApplet.handleDraw(PApplet.java:2361)
java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.lang.StringBuilder.toString(Unknown Source)
at java.lang.StackTraceElement.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.lang.Throwable.printStackTrace(Throwable.java:658)
at java.lang.Throwable.printStackTrace(Throwable.java:643)
at java.lang.ThreadGroup.uncaughtException(Unknown Source)
at java.lang.ThreadGroup.uncaughtException(Unknown Source)
at java.awt.EventDispatchThread.processException(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
An OutOfMemoryError means that your code is either using up too much memory
because of a bug (e.g. creating an array that's too large, or unintentionally
loading thousands of images), or that your sketch may need more memory to run.
If your sketch uses a lot of memory (for instance if it loads a lot of data files)
you can increase the memory available to your sketch using the Preferences window.