Quantcast
Channel: OKWAVE 閲覧数の多い質問(Java/253)【本日】
Viewing all articles
Browse latest Browse all 68675

JAVAのコンストラクタの配列について

$
0
0
C言語をずっと勉強していて、最近JAVAを勉強しているものですが、卒研で以下の様なデータ構造のテストをする以下のようなプログラムを作りました。 import java.io.*; class Cell { public int statement; public String sentence; public Cell truth; public Cell fault; } class Cells { public String func_name; public int parent; public Cell cell[] = new Cell[100]; } public class architecture { public static void main(String args[]) { Cells cells = new Cells(); cells.parent = 0; cells.func_name = "main"; cells.cell[0].statement = 1; cells.cell[0].sentence = "a = b + c"; System.out.println("parent = "+cells.parent); System.out.println("func_name = "+cells.func_name); System.out.println("statement = "+cells.cell[0].statement); System.out.println("sentence = "+cells.cell[0].sentence); } } コンパイル時にはエラーはないのですが、実行するとエラーが起きます。 そのエラーメッセージがこれです。 Exception in thread "main" java.lang.NullPointerException at architecture.main(architecture.java:22) cellsのcell型の配列がうまく生成されていないようです。 どうすればよいでしょうか? ご教授ください。

Viewing all articles
Browse latest Browse all 68675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>