-1

I have this code, it should find a pre known method's name in the chosen file:

String[] sorok = new String[listaZ.size()];
String[] sorokPlusz1 = new String[listaIdeig.size()];
boolean keresesiFeltetel1;
boolean keresesiFeltetel3;  
boolean keresesiFeltetel4;
int ind=0;

for (int i = 0; i < listaZ.size(); i++) {
    for (int id = 0; id < listaIdeig.size(); id++) {
        sorok = listaZ.get(i);
        sorokPlusz1 = listaIdeig.get(id);

        for (int j = 0; j < sorok.length; j++) {
            for (int jj = 1; jj < sorok.length; jj++) {

                keresesiFeltetel3 = (sorok[j].equals(oldName)) && (sorokPlusz1[id].startsWith("("));

                keresesiFeltetel4 = sorok[j].startsWith(oldNameV3);
                keresesiFeltetel1 = sorok[j].equals(oldName) && sorok[jj].startsWith("(");

                if (keresesiFeltetel1 || keresesiFeltetel3 || keresesiFeltetel4) {
                    Array.set(sorok, j, newName);
                    listaZarojeles.set(i, sorok);
                }
            }
         System.out.println(ind +". index, element: " +sorok[j]);
        }
        ind++;
    }
}

listaZ is an ArrayList, elements spearated by '(' and ' ', listaIdeig is this list, without the first line (because of the keresesifeltetel3) oldNameV3 is: oldName+ () I'd like to find a method's name if this is looking like this: methodname () {...

To do this I need the next line in keresesifeltetel 3, but I can't get it working properly. It's not finding anything or dropping errors. Right now it writes out the input file's element's about 15 times, then it should; and shows error on keresesifeltetel3, and:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
AllainLG
  • 108
  • 1
  • 1
  • 8
  • `keresesiFeltetel1` Please consider using attribute names in English (at least for SO posts). – Andrew Thompson Nov 11 '12 at 22:57
  • @AndrewThompson Is your comment related to [Why shouldn't I use Hungarian Notation](http://stackoverflow.com/questions/111933/why-shouldnt-i-use-hungarian-notation)? ;-) – arne.b Nov 11 '12 at 23:01
  • @arne.b No.. it's about using Czech(?) attribute names in a computer language created by English speakers & on a forum conducted in English. I guess that the 'wink' means that was a joke, ..but I don't get it. – Andrew Thompson Nov 11 '12 at 23:09
  • "keresesiFeltetel" name doesn't matter, it could be even 'b', it's just a boolean. – AllainLG Nov 11 '12 at 23:20
  • `b` is not an English name, either, so it would still be hard to recognize what it is supposed to stand for. And ArrayLists do not have lines, so someone without a hungarian phrasebook at hand will have no idea that your `sorok` variables have anything to do with your lines, whatever these are. – arne.b Nov 11 '12 at 23:33
  • I see, if a moderator see this, please delete this topic. If you don't know what ".get(i)" means, I'm sure you don't know how to help me either. "sorok" and "keresesifeltetel"s name doesn't matter, a beginner programmer would understand them, if wanted to. Until now I couldn't get answered any of my questions, it doesn't matter if I took the time to write everything in long, perfect english names, or not, but it seems if isn't everything perfectly clear, on stackflow people doesn't even try, just come here to be trolls. – AllainLG Nov 12 '12 at 11:56
  • The fact that a community of a few thousand developers manage to help each other and most newcomers, but not you, makes you think they do not try? Seriously, everyone here knows what `get(i)` means, but noone knows why you call it, or why you have a list of `String[]` in the first place, or what you want to do with it, since you never explain what your actual problem is. In good code, one would at least be able to guess from the variable names what each statement is about to do. This is not the case here, and you seem to refuse to even consider that we cannot read the problem from your mind. – arne.b Nov 12 '12 at 23:06

1 Answers1

0

I think your problem is here: sorokPlusz1[id]. id does not seem to span sorokPlusz1's range. I suspect you want to use jj and that jj should span sorokPlusz1's range instead of sorok's and that sorok[jj].startsWith("(") should be sorokPlusz1[jj].startsWith("(").

But note that I'm largely speculating as I'm not 100% sure what you're trying to do or what listaZ and listaIdeig look like.

You're creating sorok with size = listaZ's size, and then you do this: sorok = listaZ.get(i);. This is clearly not right. Not knowing the exact type of listaZ makes it difficult to tell you what's wrong with it. If it's ArrayList<String[]>, then change String[] sorok = new String[listaZ.size()]; to String[] sorok = null; or String[] sorok;. If it's ArrayList<String> then you probably want to do something more like sorok[i] = listaZ.get(i);

Now for some general notes about asking questions here: (with some repetition of what was said in the comments) (in the spirit of helping you be successful in getting answers to questions on this site).

Your question is generally unclear. After reading through your question and the code, I still have little idea what you're trying to do and what the input variables (listaZ and listaIdeig) look like.

Using non-English variable names makes it more difficult for any English speaker to help. Even changing sorok to array and keresesiFeltetelX to bX would be better (though still not great). Having long variable names that aren't understandable makes it much more difficult to read.

Comment your code. Enough comments (on almost every line) makes it much easier to understand your code.

Examples. If you have difficulty properly explaining what you want to do (in English), you can always provide a few examples which would assist your explanation a great deal (and doing this is a good idea in general). Note that a good example is both providing the input and the desired output (and the actual output, if applicable).

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138