问题描述
我想使用Point2D创建一个包含100个随机点的数组。但是,为什么Point2D的数据字段是公共的却不能访问它的数据字段?它说“ x无法解析或不是字段。”
def combine_dataframes(df):
nan_value = 0
combined = pd.concat(df,join='outer').fillna(nan_value)
return combined
dfs = [df,df2]
combined = [combine_dataframes(i) for i in dfs]
解决方法
您可能要使用setLocation。错误消息只是说,编译器不知道Point2D类型的对象上.x的含义。
,在您的代码中,points
的类型为Point2D[]
,因此points[i]
的类型为Point2D
。 Point2D
没有名为x
或y
的成员。在运行时points[i]
的 class 恰好是Point2D.Double
,它确实具有这样的成员,这一事实与编译器的分析无关。
您可以将points
声明为
Point2D.Double[] points = new Point2D.Double[100];
,或者您可以使用Point2D.setLocation()
来代替分配给成员变量,如您的其他答案所建议的那样。