Welcome to Dream.In.Code
Become a Java Expert!

Join 150,413 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,013 people online right now. Registration is fast and FREE... Join Now!




array problems

 
Reply to this topicStart new topic

array problems, getting wierd error for this array input

cosmo1
17 Mar, 2008 - 11:30 AM
Post #1

New D.I.C Head
*

Joined: 9 Feb, 2008
Posts: 4

java

import java.util.*;
import java.io.*;
public class maze {

public static void main(String[] args) {
try{

BufferedReader inFile = new BufferedReader (new FileReader ("MAZE.txt"));
String a;
String [][] ma = new String[18][20];
for(int x =0; x<20; x++)
{
a=inFile.readLine();
for(int y=0; y<18;y++ )
{
ma[x][y] = a.substring(y,y+1);
System.out.print(ma);
}
}
}
catch(Exception e)
{

}
}
}

*edit: Please use code tags in the future, thanks! Also error message was truncated for brevity. code.gif
error :
[[Ljava.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[L
java.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[L
java.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[L
java.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[Ljava.lang.String;@3e25a5[[L
.... repeating

Process completed.

help please

This post has been edited by Martyr2: 17 Mar, 2008 - 01:02 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Array Problems
17 Mar, 2008 - 01:06 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 314 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You might want to try printing out the actual array slots, not just the array.

java

// Replace the line...
System.out.print(ma);

// With the line...
System.out.print(ma[x][y]);


The problem is that you dump in a value into your 2D array but then you try printing the whole array instead of the slot you just dumped the value into. Thus it is returning data that shows you have a series of string array spots setup (notice the message has java.lang.String in it).

I hope that solves the problem for you.

"At DIC we be array subscript printing code ninjas!" decap.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:02PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month