![](http://oshiete.xgoo.jp/images/v2/pc/qa/question_title.png?8acaa2e)
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 …
![「三角形オブジェクト」の質問画像](http://oshiete.xgoo.jp/_/bucket/oshietegoo/images/media/0/542395957_57eb3f13c2cf6/M.png)
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で質問しましょう!
似たような質問が見つかりました
- TOEFL・TOEIC・英語検定 英検準1級英作文の添削をお願いします。 ポイントはCurriculumとGlobalizationを 4 2023/05/29 11:33
- 英語 できるだけ直訳で英語の翻訳をお願いします。(英語→日本語) 1 2022/10/15 20:59
- ボランティア ウクライナ人からどういうこと? 6 2022/03/28 07:37
- 戦争・テロ・デモ ウクライナ、メル友に五千円要求されてさ 1 2022/04/02 09:38
- 英語 この英文は格調高いのでしょうか? 3 2022/06/03 18:55
- 哲学 Humility is ... appearance.の一番古い出典となる書物は何で著者は誰ですか? 11 2022/04/21 03:19
- 英語 この英文は平易な反面格調高いですか? 1 2023/01/15 12:04
- C言語・C++・C# [至急]Project Euler:#18Maximum path sum Iコード、入力出力、解説 4 2022/09/24 02:49
- C言語・C++・C# [至急]Project Euler:#17Number letter countsコード入力出力解説 2 2022/09/24 02:46
- 英語 One technique that may be used is to have the surg 1 2023/03/05 20:43
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
ワイルドカード<?>と型パラメー...
-
TextFieldの文字の折り返し
-
オブジェクトとコントロールっ...
-
bmp画像をjpegやpng画像に圧縮...
-
Excelで =EMBED("Acrobat Docu...
-
オブジェクトレベルとメタレベル
-
パワーポイントのVBAでテキスト...
-
ワードで画像をドロップすると...
-
Google Apps Scriptの時刻の計算
-
javaでは基本型の参照渡しは無...
-
jQueryのvar jQueryの仕組みに...
-
error C2712: オブジェクト ア...
-
LISTBOXの内容が更新されま...
-
三角形オブジェクト
-
リンク色の取得方法
-
オブジェクトとは、わかりやす...
-
VBAの初心者です。
-
VBA 同じ名前のオブジェクトを...
-
インデザインのテキスト回り込み
-
VBAのWindowオブジェクトとWork...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
0 == False はいいけど
-
パワーポイントのVBAでテキスト...
-
C#でフォームのオブジェクト名...
-
Excelで =EMBED("Acrobat Docu...
-
VBAのWindowオブジェクトとWork...
-
JAVAからHTMLへ値を返す方法
-
EXCEL VBAにて動的にCheckBOXを...
-
ワイルドカード<?>と型パラメー...
-
COMコンポーネントって何?
-
VBA 同じ名前のオブジェクトを...
-
Object型からDouble型へのキャスト
-
ビジュアルC++でボタンの有...
-
error C2712: オブジェクト ア...
-
bmp画像をjpegやpng画像に圧縮...
-
戻り値がクラスオブジェクト
-
オブジェクト名をforループ内で...
-
Vbで通常使用するプリンターを...
-
時間帯判定をする。
-
LISTBOXの内容が更新されま...
-
Webアプリケーションのエラーメ...
おすすめ情報