Article View: aus.computers.java
Article #846Trouble accessing values in a 2D array
From: Jman
Date: Wed, 10 May 2000 00:00
Date: Wed, 10 May 2000 00:00
67 lines
2375 bytes
2375 bytes
I have a class which stores doubles in a 2D array.
I declare these:
private double [][] distance;
private double [][] coords;
I read data from a file placing it into coords array:
public void enterDoubleXY(double d, int XY)
{
double [ ][ ] coords = new double[10][2];
switch(XY)
{
case 0:
//store values into coords array
if(ac == 0)
{
coords[0][0] = d;
ac++;
}
else
etc......
public double getCoords(int a, int b)
{
return coords[a][b];
}
private void setDistanceArray()
{
double [][] distance = new double[10][10];
double xd;
double yd;
String city[][] = {{"A"},{"B"},{"C"},{"D"},{"E"},{"F"},{"G"},{"H"},
{"I"},{"J"}};
for(int i=0;i<size;i++)
{
for(int j=i+1;j<size;j++)
{
System.out.print("to here!");
//problem -- null pointer exception!
System.out.print(getCoords(0,0) - getCoords(1,0));
xd = getCoords(i,0)- getCoords(j,0);
yd = getCoords(i,1)- getCoords(j,1);
//xd=coords[i][0] - coords[j][0];
//yd=coords[i][1] - coords[j][1];
Now, why do I get a Null Pointer Exception when
I have already stored the values into coords array?
This is very strange!
Thanks,
J
Sent via Deja.com http://www.deja.com/
Before you buy.
Technical Details
Message-ID:
<8fbd5b$kbd$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<39189457.3527647@news.melbpc.org.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 13da4b,1002517bab792639,start X-Google-Attributes: gid13da4b,public X-Google-Thread: 10d6db,1002517bab792639,start X-Google-Attributes: gid10d6db,public From: Jman <j_trak@yahoo.com> Subject: Trouble accessing values in a 2D array Date: 2000/05/10 Message-ID: <8fbd5b$kbd$1@nnrp1.deja.com> X-Deja-AN: 621500246 References: <39189457.3527647@news.melbpc.org.au> X-Http-Proxy: 1.1 proxy.freeonline.com.au:8000 (Squid/2.2.STABLE4), 1.0 x35.deja.com:80 (Squid/1.1.22) for client 172.17.20.248, 203.76.17.27 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Wed May 10 10:20:38 2000 GMT X-MyDeja-Info: XMYDJUIDjtrak1 Newsgroups: aus.computers.java,comp.lang.programmer.java X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)