• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Failed to copy two dimensional array

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
In the following code....

public class Alignment {
private String[] strs;
private char padSymbol = '-';
private char[][] charArray;

public Alignment(){

}

public Alignment(String s1, String s2){
strs = new String[2];
setFirstString(s1);
setSecondString(s2);
}

public char[][] toArray(){
for(int i = 0; i < strs.length; i++){
int j = strs[i].length();
charArray[i] = strs[i].toCharArray();}
return charArray;
}
}

When I try to run the class by using other Test.java I am getting error in the toArray() method, in the line
charArray[i] = strs[i].toCharArray();
charArray is a two dimensional array.
strs is one dimensional array which consists of two strings s1 and s2.

I am getting an error as "Exception processing async thread queue". It compiles fine.

Can any one help in coming out of this issue.

Regards,
Ravindra.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know if I'm missing something, but the code you posted seems a bit odd - e.g. not sure why charArray is an instance variable - couldn't it just be local ?

Anyway - with a bit of tweaking to get it to compile and adding a main method to test it, it gave me a null pointer because charArray was never initialiased, I've tweaked it a bit more below to initialise it - is that any good ?



[ April 23, 2007: Message edited by: michael warren ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic