【问题标题】:I can't understand the following Errors on my Unfolding Maps Project我无法理解展开地图项目中的以下错误
【发布时间】:2019-08-12 07:45:23
【问题描述】:

我正在尝试使用展开地图显示整个世界的地震数据,但我遇到了我不理解的错误。请帮助我解决这些错误

过去,我曾尝试通过将布尔值设置为 true 来离线运行地图,但没有成功。

问题来自 Coursera,以作业的形式出现。我正在解决此作业中的问题

Using OpenGLMapDisplay with processing.opengl.PGraphics3D
Exception in thread "Animation Thread" java.lang.NullPointerException
    at module3.EarthquakeCityMap.setup(EarthquakeCityMap.java:102)
    at processing.core.PApplet.handleDraw(PApplet.java:2365)
    at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:873)
    at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:690)
    at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:672)
    at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1383)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1277)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1131)
    at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1394)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:301)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

 List<Marker> markers = new ArrayList<Marker>();

    //Use provided parser to collect properties for each earthquake
    //PointFeatures have a getLocation method
    List<PointFeature> earthquakes = ParseFeed.parseEarthquake(this, earthquakesURL);

    for (PointFeature eq: earthquakes) {
        markers.add(new SimplePointMarker(eq.getLocation(), eq.getProperties()));
    }

    // Add the markers to the map so that they are displayed
    map.addMarkers(markers);



int yellow = color(255,255,0);
int gray = color(150,150,150);

for(Marker mk : markers) {
    if ((int) mk.getProperty("year") > 2000) {
        mk.setColor(yellow);
    }
    else {
        mk.setColor(gray);
    }
}


}


@SuppressWarnings("unused")
private SimplePointMarker createMarker(PointFeature feature)
{  
    // To print all of the features in a PointFeature (so you can see what they are)
    // uncomment the line below.  Note this will only print if you call createMarker 
    // from setup
    //System.out.println(feature.getProperties());

    // Create a new SimplePointMarker at the location given by the PointFeature
    SimplePointMarker marker = new SimplePointMarker(feature.getLocation());

    Object magObj = feature.getProperty("magnitude");
    float mag = Float.parseFloat(magObj.toString());

    // Here is an example of how to use Processing's color method to generate 
    // an int that represents the color yellow.  
    int yellow = color(255, 255, 0);


    // Finally return the marker
    return marker;
}

public void draw() {
    background(10);
    map.draw();
}

【问题讨论】:

    标签: java unfoldingmap


    【解决方案1】:

    这个例外

    Exception in thread "Animation Thread" java.lang.NullPointerException
    

    这里是

    at module3.EarthquakeCityMap.setup(EarthquakeCityMap.java:102)
    

    因此,您需要进入“EarthquakeCityMap.java”,第 102 行并找出可能导致空指针异常的原因

    【讨论】:

    • 亲爱的布兰登,这是第 102 行
    • for(Marker mk: 标记) { if ((int) mk.getProperty("year") > 2000) { mk.setColor(yellow); } 其他 { mk.setColor(灰色); } }
    • 但我是初学者而且我不知道它接受和返回什么类型的参数
    • 好的,所以如果我们正在遍历一个列表,我们需要确保它不为空(if(markers != null),以及 mk.getProperty("year") 的结果,我们还需要在将其转换为 int 之前确保它不是 null (以及检查它是否可以转换为 int)( if(mk.getProperty("year") != null && mk.getProperty( "年") instanceOf int)
    • 如果这就是解决问题的原因,请将其标记为答案,或者如果它有所不同,请发布您对问题的答案并标记为已回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 2021-04-10
    • 1970-01-01
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多