2013-02-26 230 views
0

我需要一些帮助,我不知道我在哪里得到的错误在这里.. 我需要保存输入字符串的每个字符在2D-Array。我也输入了行和列数字和方向ih水平垂直,并从那里我评估字符串的每个字符使用charAt并将其保存在基于输入的行和列编号的数组中的特定位置。 这是我的代码..保存输入字符串字符到一个二维数组

  playedword = word.getText().toString(); 
      evalrow = Integer.parseInt(inrow.getText().toString()); 
      evalcolumn = Integer.parseInt(incolumn.getText().toString()); 
      evalorient = inorient.getText().toString(); 
      if(evalorient.equals("H")){ 
       orientation=0; //horizontal 
      }else if(evalorient.equals("V")){ 
       orentation=1; //vertical 
      } 
      if(playedword.length()>0){ 
       if(vertical == 0){ 
        for(int u=0; u<playedword.length(); u++){ 
         arr2[evalrow][evalcolumn+u] = playedword.charAt(u); 
        } 
       }else if(vertical == 1){ 
        for(int u=0; u<playedword.length(); u++){ 
         arr2[evalrow+u][evalcolumn] = playedword.charAt(u); 
        } 
       } 
      } 

arr2是我的2维数组,具有6x6维数..... 我不知道这里的错误..请帮助

+3

http://imgur.com/jacoj – 2013-02-26 04:24:23

+1

@kathy能否请您发布错误消息,你得到的程序中断时?应该看起来像“追溯(最近调用最后一个): 文件”tb.py“,第10行,在 a()” – chm 2013-02-26 04:29:02

回答

0

从字符串二维数组转换试试这个逻辑

char[][] array = new char[5][5]; 
String str="hello how are you my dear"; 
for (int i = 0; i < 5; ++i) 
{ 
    str.getChars(i*5, (i*5)+5, array[i], 0); // str is the 25-char string 
}