How to solve java.lang.RuntimeException: The P3D renderer is not in the class path. while running Processing from Eclipse?

huangapple 未分类评论53阅读模式
英文:

How to solve java.lang.RuntimeException: The P3D renderer is not in the class path. while running Processing from Eclipse?

问题

I'll post the whole code:

import controlP5.ControlP5;
import processing.core.*;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PImage;
import processing.core.PShape;
import processing.event.MouseEvent; 

import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

public class Two_Maps_Texture extends PApplet {

PFont title;
PFont label;
PImage worldMap;
PImage skyBackground;
PShape box;
Table table, table2;
int rowCount;
float x1, y1, z1, x2, y2, z2;

// Interaction Zoom and Pan Variables:
float zoom = 600;
float panLeft = 0;
float panTop = 0;

DestinationToTrip fromUSA;
DestinationToTrip toUSA;

ControlP5 button1;
ControlP5 button2;
boolean isFromUSAVisible = false;
boolean isToUSAVisible = false;

public void setup() {
  
  table = new Table("From_USA_Coordinates.tsv");
  table2 = new Table("To_USA.tsv");
  rowCount = table.getRowCount();
  
  worldMap = loadImage("world.topo.bathy.200406.3x5400x2700.jpg"); 
  //skyBackground = loadImage("Screen-Shot-2018-04-28-at-7.46.41-PM");
  //skyBackground.resize(1400, 800);
  worldMap.resize(500, 300);
  textureMode(NORMAL);
  fill(255);
  //stroke(color(44,48,32));
  box = createShape(BOX, -650, 300, 0);
  box.beginShape(BOX);
  box.endShape();  
  box.setTexture(worldMap);
  
  fromUSA = new DestinationToTrip(table);
  toUSA = new DestinationToTrip(table2);
  
  title = loadFont("Tahoma-Bold-48.vlw");
  label = loadFont("Tahoma-48.vlw");
  
  fill(150);
  
  //pushMatrix();
    camera();
    button1 = new ControlP5(this);
    button1.addButton("From_USA_to_Other_Countries").setValue(1).setPosition((100), (height-150)).setSize(200, 100).setColorBackground(color(76,112,170)).setVisible(true);
    
    button2 = new ControlP5(this);
    button2.addButton("From_Other_Countries_to_USA").setValue(0).setPosition((350), (height-150)).setSize(200, 100).setColorBackground(color(76,112,170));
  //popMatrix();
}

public void draw() {  
  background(0xff181c70);  
  fill(0);  
  titlesAndLegends(); 
  boxSetup();
  
  if(isFromUSAVisible == true) {
      fromUSA.displayCurves(table, 0xff4185bf);
  }
  
  if(isToUSAVisible == true){
    pushMatrix();
      toUSA.displayCurves(table2, 0xffdfb34a);
    popMatrix();
  }
}

public void boxSetup(){
   camera(panLeft, zoom , zoom, panLeft, -190, panTop, 0, 1, 0);   // eye(0, 600, 600) center(0, 0, 0) up(0, 1, 0)
  
  pushMatrix();
    translate(-350, 0, 0);
    shape(box);
  popMatrix();  
  
  pushMatrix();
    translate(350, 0, 0);
    shape(box);
  popMatrix();  
}

public void titlesAndLegends() {
  pushMatrix();
    camera();
    textAlign(CENTER);
    textSize(40);
    fill(0xff91cd83);   
    textFont(title);
    text("Flights Involving USA - 2019", width/2, 90);  
    textFont(label);
    if(isFromUSAVisible == true) {
      textSize(20);
      fill(0xff4185bf);
      text("USA to Other Country", width/2, 150);
    } if(isToUSAVisible == true) {
      textSize(20);
      fill(0xffdfb34a);
      text("Other Countries to USA", width/2, 180);
    }
  popMatrix();
}

public void mouseDragged() {
  if((mouseX- pmouseX) > 0){
    panLeft -= 5;
  } else {
    panLeft += 5;
  }
}

public void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  if(e == 1) {
    zoom += 30;
  }else {
    zoom -= 30;
  } 
}

public void From_USA_to_Other_Countries() {
  if(!isFromUSAVisible) {
    isFromUSAVisible = true;
  }else {
    isFromUSAVisible = false;
  }
}

public void From_Other_Countries_to_USA() {
  if(!isToUSAVisible) {
    isToUSAVisible = true;
  }else {
    isToUSAVisible = false;
  }
}
class DestinationToTrip {
  
  Table table;
  int rowCount;
  float x1, y1, z1, x2, y2, z2;
  
  int stroke = 0xffF05252;
  
 
  
  DestinationToTrip(Table table) {      
    this.table = table;    
  }
  
  public void displayCurves(Table table, int stroke) {   
    rowCount = table.getRowCount();
    table = new Table("From_USA_Coordinates.tsv");

  pushMatrix();
    // To use the center of the left box as center coordinates
    translate(-350, 0, 0);    
    textSize(15);

  for(int row = 1; row < rowCount; row++) {

    float USALatitude = table.getFloat(row, 3);
    float USALongitude = table.getFloat(row, 4);
    String countryName = table.getString(row,1);    

    // Mapped Within X-axis of the left side map box

    float mappedLatitude = map(USALatitude,-90, 90, 150, -150); // Latitude is in Y axis
    float mappedLongitude = map(USALongitude, -180, 180, -325, 325); // Longitude in X Axis
    x1 = mappedLongitude;
    y1 = mappedLatitude;
    z1 = 0;    

    float tripCountryLatitude = table.getFloat(row, 5);
    float tripCountryLongitude = table.getFloat(row, 6);     
    float tripLatitude = map(tripCountryLatitude, -90, 90, 150, -150); // In Y, same mapping
    float tripLongitude = map(tripCountryLongitude, -180, 180, 375, 1025); 

    // In X, having the position of the right box depending on the coordinates center
    x2 = tripLongitude;
    y2 = tripLatitude;
    z2 = 0;    

    float zOff = map(0, 0, height, 300, 0); // Move mouse up and down    

    float a = (x2

<details>
<summary>英文:</summary>

I&#39;ll post the whole code:

    import controlP5.ControlP5;
    import processing.core.*;
    import processing.core.PApplet;
    import processing.core.PFont;
    import processing.core.PImage;
    import processing.core.PShape;
    import processing.event.MouseEvent; 
    
    import processing.data.*; 
    import processing.event.*; 
    import processing.opengl.*; 
    
    public class Two_Maps_Texture extends PApplet {
    
    PFont title;
    PFont label;
    PImage worldMap;
    PImage skyBackground;
    PShape box;
    Table table, table2;
    int rowCount;
    float x1, y1, z1, x2, y2, z2;
    
    //Interaction Zoom and Pan Variables:
    float zoom = 600;
    float panLeft = 0;
    float panTop = 0;
    
    
    DestinationToTrip fromUSA;
    DestinationToTrip toUSA;
    
    ControlP5 button1;
    ControlP5 button2;
    boolean isFromUSAVisible = false;
    boolean isToUSAVisible = false;
    
    
    public void setup() {
      
      table = new Table(&quot;From_USA_Coordinates.tsv&quot;);
      table2 = new Table(&quot;To_USA.tsv&quot;);
      rowCount = table.getRowCount();
      
      worldMap = loadImage(&quot;world.topo.bathy.200406.3x5400x2700.jpg&quot;); 
      //skyBackground = loadImage(&quot;Screen-Shot-2018-04-28-at-7.46.41-PM&quot;);
      //skyBackground.resize(1400, 800);
      worldMap.resize(500, 300);
      textureMode(NORMAL);
      fill(255);
      //stroke(color(44,48,32));
      box = createShape(BOX, -650, 300, 0);
      box.beginShape(BOX);
      box.endShape();  
      box.setTexture(worldMap);
      
      fromUSA = new DestinationToTrip(table);
      toUSA = new DestinationToTrip(table2);
      
      title = loadFont(&quot;Tahoma-Bold-48.vlw&quot;);
      label = loadFont(&quot;Tahoma-48.vlw&quot;);
      
      fill(150);
      
      //pushMatrix();
        camera();
        button1 = new ControlP5(this);
        button1.addButton(&quot;From_USA_to_Other_Countries&quot;).setValue(1).setPosition((100), (height-150)).setSize(200, 100).setColorBackground(color(76,112,170)).setVisible(true);
        
        button2 = new ControlP5(this);
        button2.addButton(&quot;From_Other_Countries_to_USA&quot;).setValue(0).setPosition((350), (height-150)).setSize(200, 100).setColorBackground(color(76,112,170));
      //popMatrix();
    }
    
    public void draw() {  
      background(0xff181c70);  
      fill(0);  
      titlesAndLegends(); 
      boxSetup();
      
      if(isFromUSAVisible == true) {
          fromUSA.displayCurves(table, 0xff4185bf);
      }
      
      if(isToUSAVisible == true){
        pushMatrix();
          toUSA.displayCurves(table2, 0xffdfb34a);
        popMatrix();
      }
    }
    
    public void boxSetup(){
       camera(panLeft, zoom , zoom, panLeft, -190, panTop, 0, 1, 0);   // eye(0, 600, 600) center(0, 0, 0) up(0, 1, 0)
      
      pushMatrix();
        translate(-350, 0, 0);
        shape(box);
      popMatrix();  
    
      pushMatrix();
        translate(350, 0, 0);
        shape(box);
      popMatrix();  
    }
    
    public void titlesAndLegends() {
      pushMatrix();
        camera();
        textAlign(CENTER);
        textSize(40);
        fill(0xff91cd83);   
        textFont(title);
        text(&quot;Flights Involving USA - 2019&quot;, width/2, 90);  
        textFont(label);
        if(isFromUSAVisible == true) {
          textSize(20);
          fill(0xff4185bf);
          text(&quot;USA to Other Country&quot;, width/2, 150);
        } if(isToUSAVisible == true) {
          textSize(20);
          fill(0xffdfb34a);
          text(&quot;Other Countries to USA&quot;, width/2, 180);
        }
      popMatrix();
    }
    
    public void mouseDragged() {
      if((mouseX- pmouseX) &gt; 0){
        panLeft -= 5;
      } else {
        panLeft += 5;
      }
    }
    
    public void mouseWheel(MouseEvent event) {
      float e = event.getCount();
      if(e == 1) {
        zoom += 30;
      }else {
        zoom -= 30;
      } 
    }
    
    public void From_USA_to_Other_Countries() {
      if(!isFromUSAVisible) {
        isFromUSAVisible = true;
      }else {
        isFromUSAVisible = false;
      }
    }
    
    public void From_Other_Countries_to_USA() {
      if(!isToUSAVisible) {
        isToUSAVisible = true;
      }else {
        isToUSAVisible = false;
      }
    }
    class DestinationToTrip {
      
      Table table;
      int rowCount;
      float x1, y1, z1, x2, y2, z2;
      
      int stroke = 0xffF05252;
      
     
      
      DestinationToTrip(Table table) {      
        this.table = table;    
      }
      
      public void displayCurves(Table table, int stroke) {   
        rowCount = table.getRowCount();
        table = new Table(&quot;From_USA_Coordinates.tsv&quot;);
     
      pushMatrix();
        // To use the center of the left box as center coordinates
        translate(-350, 0, 0);    
        textSize(15);
    
      for(int row = 1; row &lt; rowCount; row++) {
    
        float USALatitude = table.getFloat(row, 3);
        float USALongitude = table.getFloat(row, 4);
        String countryName = table.getString(row,1);    
    
        //Mapped Within X-axis of the left side map box
    
        float mappedLatitude = map(USALatitude,-90, 90, 150, -150); // Latitude is in Y axis
        float mappedLongitude = map(USALongitude, -180, 180, -325, 325); // Longitude in X Axis
        x1 = mappedLongitude;
        y1 = mappedLatitude;
        z1 = 0;    
    
        float tripCountryLatitude = table.getFloat(row, 5);
        float tripCountryLongitude = table.getFloat(row, 6);     
        float tripLatitude = map(tripCountryLatitude, -90, 90, 150, -150); // In Y, same mapping
        float tripLongitude = map(tripCountryLongitude, -180, 180, 375, 1025); 
    
        // In X, having the position of the right box depending on the coordinates center
        x2 = tripLongitude;
        y2 = tripLatitude;
        z2 = 0;    
    
        float zOff = map(0, 0, height, 300, 0); // Move mouse up and down    
    
        float a = (x2-x1)/3;
        float b = (y2-y1)/3;
    
        stroke(stroke);
        noFill();
    
        bezier(x1, y1, z1,                 // First point
             x1 + a, y1 + b, z1 + zOff,  // First intermediate point
             x2 - a, y2 - b, z2 + zOff,  // Second intermediate point
             x2, y2, z2); 
         
        //rotate(PI); 
        stroke(255);
        fill(255);
        text(countryName, x2-10, y2+10, z2+20);
      }
    
      popMatrix();
    
    }
    
      }
    class Table {
      int rowCount;
      String[][] data;
      
      
      Table(String filename) {
        String[] rows = loadStrings(filename);
        data = new String[rows.length][];
        
        for (int i = 0; i &lt; rows.length; i++) {
          if (trim(rows[i]).length() == 0) {
            continue; // skip empty rows
          }
          if (rows[i].startsWith(&quot;#&quot;)) {
            continue;  // skip comment lines
          }
          
          // split the row on the tabs
          String[] pieces = split(rows[i], TAB);
          // copy to the table array
          data[rowCount] = pieces;
          rowCount++;
          
          // this could be done in one fell swoop via:
          //data[rowCount++] = split(rows[i], TAB);
        }
        // resize the &#39;data&#39; array as necessary
        data = (String[][]) subset(data, 0, rowCount);
      }
      
      
      public int getRowCount() {
        return rowCount;
      }
      
      
      // find a row by its name, returns -1 if no row found
      public int getRowIndex(String name) {
        for (int i = 0; i &lt; rowCount; i++) {
          if (data[i][0].equals(name)) {
            return i;
          }
        }
        println(&quot;No row named &#39;&quot; + name + &quot;&#39; was found&quot;);
        return -1;
      }
      
      
      public String getRowName(int row) {
        return getString(row, 0);
      }
    
    
      public String getString(int rowIndex, int column) {
        return data[rowIndex][column];
      }
    
      
      public String getString(String rowName, int column) {
        return getString(getRowIndex(rowName), column);
      }
    
      
      public int getInt(String rowName, int column) {
        return parseInt(getString(rowName, column));
      }
    
      
      public int getInt(int rowIndex, int column) {
        return parseInt(getString(rowIndex, column));
      }
    
      
      public float getFloat(String rowName, int column) {
        return parseFloat(getString(rowName, column));
      }
    
      
      public float getFloat(int rowIndex, int column) {
        return parseFloat(getString(rowIndex, column));
      }
      
      
      public void setRowName(int row, String what) {
        data[row][0] = what;
      }
    
    
      public void setString(int rowIndex, int column, String what) {
        data[rowIndex][column] = what;
      }
    
      
      public void setString(String rowName, int column, String what) {
        int rowIndex = getRowIndex(rowName);
        data[rowIndex][column] = what;
      }
    
      
      public void setInt(int rowIndex, int column, int what) {
        data[rowIndex][column] = str(what);
      }
    
      
      public void setInt(String rowName, int column, int what) {
        int rowIndex = getRowIndex(rowName);
        data[rowIndex][column] = str(what);
      }
    
      
      public void setFloat(int rowIndex, int column, float what) {
        data[rowIndex][column] = str(what);
      }
    
    
      public void setFloat(String rowName, int column, float what) {
        int rowIndex = getRowIndex(rowName);
        data[rowIndex][column] = str(what);
      }  
    }
      public void settings() {  size(1400, 800, &quot;P3D&quot;); }
      static public void main(String[] passedArgs) {
        String[] appletArgs = new String[] { &quot;Two_Maps_Texture&quot; };
        if (passedArgs != null) {
          PApplet.main(concat(appletArgs, passedArgs));
        } else {
          PApplet.main(appletArgs);
        }
      }
    }



&gt; java.lang.RuntimeException: The P3D renderer is not in the class path.
&gt; 	at processing.core.PApplet.makeGraphics(PApplet.java:2311)
&gt; 	at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2345)
&gt; 	at processing.core.PApplet.initSurface(PApplet.java:10983)
&gt; 	at processing.core.PApplet.runSketch(PApplet.java:10922)
&gt; 	at processing.core.PApplet.main(PApplet.java:10620)
&gt; 	at Two_Maps_Texture.main(Two_Maps_Texture.java:355)

I&#39;ve imported all the jar files like the resources tell me to but still I get the error.



</details>


# 答案1
**得分**: 0

请确保在构建路径中添加 jogl 和 gluegen 库以支持 `P3D`(OpenGL渲染器

以下是在 macOS 上的示例使用与您的平台操作系统和 CPU 架构相对应的[jar 文件][1]

[![在 Eclipse 项目中的 gluegen-rt 和 jogl jar 库位置][2]][2]

这些库文件应位于 Processing 安装文件夹中的 `Java/core/library`

一旦您将相关的 jogl 和 gluegen-rt jar 文件添加到项目中并将它们添加到构建路径中您就应该能够无错误地进行编译

  [1]: https://github.com/processing/processing/tree/master/core/library
  [2]: https://i.stack.imgur.com/7cCf7.jpg

<details>
<summary>英文:</summary>

Ensure you add the jogl and gluegen libraries to the build path as well for `P3D`(OpenGL) renderer support.

Here&#39;s an example on OSX: use the [jar files][1] specific to your platform (OS and CPU architecture)

[![gluegen-rt and jogl jar libraries location in in the eclipse project][2]][2]

They should be within the Processing install folder within `Java/core/library`.

Once you&#39;ve added the relevant jogl and gluegen-rt jar files to the project and added them to the Build Path you should be able to compile with no errors

  [1]: https://github.com/processing/processing/tree/master/core/library
  [2]: https://i.stack.imgur.com/7cCf7.jpg

</details>



# 答案2
**得分**: 0

以下是翻译好的内容

在设置Processing应用程序时您需要将要在size()函数中使用的渲染器类的名称传递进去

在Processing IDE/环境中使用OpenGL时您使用的是`"P3D"`,但是当您使用自定义IDE例如Eclipse您需要使用`PConstants.P3D`。这是一个字符串常量其值为`"processing.opengl.PGraphicsOpenGL"` - 实际的OpenGL渲染器类的名称

```java
public void settings() {
    size(W, H, processing.core.PConstants.P3D);
}
英文:

When you set up your Processing app you need to to pass in the name of the renderer class you want to use to the size() function.

In the Processing IDE/environment for OpenGL you use &quot;P3D&quot;, but when you use a custom IDE like Eclipse you need to use PConstants.P3D. That is a string constant which value is &quot;processing.opengl.PGraphicsOpenGL&quot; - the name of the actual OpenGL render class.

public void settings() {
	size(W, H, processing.core.PConstants.P3D);
}

huangapple
  • 本文由 发表于 2020年4月11日 12:05:08
  • 转载请务必保留本文链接:https://java.coder-hub.com/61152015.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定