
java
三角形のオブジェクトを作ってる最中なのですが
エラーが多くて動きません。
自分が思うには他のクラス(Circle.java,Line.java,Point.java)と連携してないのかなと思ってます。
以下ソースです。
public class Sample70 {
public static void main(String[] args) {
Point o;//点オブジェクト
Line line;//線lineオブジェクト
Triangle triangle;//三角形triangleオブジェクト
Circle circle;//円circleオブジェクト
o = new Point();
line = new Line();
triangle = new Triangle();
circle = new Circle();
o.x = 0;
o.y = 0;
Point point = new Point();
point.x = 2;
point.y = 3;
line.p0 = point;
point = new Point();
point.x = 4;
point.y = 9;
line.p1 = point;
triangle.p0 = new Point();
triangle.p0.x = 3;
triangle.p0.y = 9;
triangle.p1 = new Point();
triangle.p1.x = 4;
triangle.p1.y = 3;
triangle.p2 = new Point();
triangle.p2.x = 4;
triangle.p2.y = 6;
circle.p0 = new Point();
circle.p0.x = 10;
circle.p0.y = 10;
circle.r = 1;
System.out.println(o.x);
System.out.println(line.p0.y);
System.out.println(line.p1.x);
System.out.println(triangle.p2.y);
System.out.println(circle.r);
}
}
エラーメッセージは
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
x cannot be resolved or is not a field
y cannot be resolved or is not a field
x cannot be resolved or is not a field
y cannot be resolved or is not a field
p0 cannot be resolved or is not a field
x cannot be resolved or is not a field
y cannot be resolved or is not a field
p1 cannot be resolved or is not a field
p0 cannot be resolved or is not a field
p0 cannot be resolved or is not a field
p0 cannot be resolved or is not a field
p1 cannot be resolved or is not a field
p1 cannot be resolved or is not a field
p1 cannot be resolved or is not a field
p2 cannot be resolved or is not a field
p2 cannot be resolved or is not a field
p2 cannot be resolved or is not a field
p0 cannot be resolved or is not a field
p0 cannot be resolved or is not a field
p0 cannot be resolved or is not a field
r cannot be resolved or is not a field
x cannot be resolved or is not a field
p0 cannot be resolved or is not a field
p1 cannot be resolved or is not a field
p2 cannot be resolved or is not a field
r cannot be resolved or is not a field
at Sample70.main(Sample70.java:14)
多分フィールドがないよという意味なのかも知れませんが
中々実行がうまくいかず困ってます。
駄目出しで良いのでご教授頂ければと思います。
http://www.atmarkit.co.jp/ait/articles/0503/19/n …

No.3ベストアンサー
- 回答日時:
> x cannot be resolved or is not a field
おそらくは
クラス Point のフィールド x のアクセス修飾子が省略されており、
クラス Point と Sample70 が別のパッケージ(ディレクトリ)なので、
フィールドの制限である「同じパッケージ内のみ」に引っかかり、
Sample70 から x が見つからずにコンパイルエラーとなっています。
修正するならば、
1. フィールド x に public の修飾子を付ける (おすすめ)
2. クラス Point と Sample70 を同じパッケージにする
参考) Java のアクセス修飾子
private : 同じクラスのみ
protected : 同じパッケージ内 または サブクラス
public : すべて
省略時 : 同じパッケージ内のみ
参考) Java 言語仕様 / セキュリティの概要
https://docs.oracle.com/javase/jp/8/docs/technot …
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
VBSでのステートメントの末尾が...
-
ASP.net 教えてください!!(...
-
C#でフォームのオブジェクト名...
-
インラインフレームがときどき...
-
オブジェクト配列の各メンバを...
-
JSPのスレッドセーフについて
-
写真が合成か調べる方法
-
Object型からDouble型へのキャスト
-
CoCreateInstanceでエラーになる。
-
オブジェクトレベルとメタレベル
-
パワーポイントのVBAでテキスト...
-
Google Apps Scriptの時刻の計算
-
VBA 同じ名前のオブジェクトを...
-
サーブレットのクラス図について。
-
C++で*thisは何を指しているの...
-
中学のクラス数
-
「タイプ初期化子が例外をスロ...
-
ヒグマを撃退
-
【sendkeysメソッドが動かずに...
-
エクセルVBAで、条件に一致する...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
パワーポイントのVBAでテキスト...
-
VBA 同じ名前のオブジェクトを...
-
Excelで =EMBED("Acrobat Docu...
-
COMコンポーネントって何?
-
VBAのWindowオブジェクトとWork...
-
ワイルドカード<?>と型パラメー...
-
error C2712: オブジェクト ア...
-
Object型からDouble型へのキャスト
-
C#でフォームのオブジェクト名...
-
質問すいません。 javascriptの...
-
EXCEL VBAにて動的にCheckBOXを...
-
ASP.net 教えてください!!(...
-
オブジェクトレベルとメタレベル
-
0 == False はいいけど
-
ActiveDirectoryのユーザ情報の...
-
Accessの連結・非連結オブジェ...
-
Vbで通常使用するプリンターを...
-
ビジュアルC++でボタンの有...
-
LISTBOXの内容が更新されま...
-
サーブレットのクラス図について。
おすすめ情報