简体   繁体   English

2d字符串数组NullPointerException(java)

[英]2d String Array NullPointerException (java)

I am currently creating a java application in which I have a 2d array which I want to get some data into. 我目前正在创建一个Java应用程序,其中有一个2d数组,我想将一些数据放入其中。

I am creating the 2d array as such 我正在像这样创建2d数组

String[][] addressData;

and then when I am trying to put data in I am using reference the exact position in the 2d array I want to enter the data into eg 然后当我尝试将数据放入时,我正在使用2D数组中的确切位置,我想将数据输入到例如

addressData[0][0] = "String Data";

The program compiles yet when I run I get a NullPointerException error. 该程序在运行时仍会编译,但出现NullPointerException错误。 Am I using the wrong method to enter data into this 2d array? 我使用错误的方法将数据输入到2d数组中吗?

String[][] addressData - this is just declaration, you have to create actual object String[][] addressData = new String[size][size]; String [] [] addressData-这仅仅是声明,您必须创建实际的对象String [] [] addressData = new String [size] [size];

Btw, There is no 2d arrays in java String[][] is an array of arrays of strings 顺便说一句,java中没有二维数组String [] []是字符串数组的数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM