java - Array omitting lines in one part of code, but showing it in another -
so i'm creating string[] , in section of code miss lines of code i'm checking for! *please note: know not best approach checking, "proof of concept" , changed later on. anyway, here code gives me problem:
private void checkmethods() { (int = 0; < array.length; i++) { string s = array[i]; system.out.println(s); if(array[i].contains("onenable()")) { system.out.println("enable"); array[i] = methodupdate.onenable; } else if (isondisable(s)) { system.out.println("disable"); array[i] = methodupdate.ondisable; } else if (isoverride(s)) { if (checknextline(array[i++])) { array[i] = ""; } } } }
now returns following:
public class dummybukkitclass extends javaplugin { @override // profound code can found here } @override // profound code ending =( } }
however in next code returns need too:
public void updatefile(file file) throws ioexception { bufferedreader br = null; pw = null; seek { br = new bufferedreader(new filereader("classes/dummybukkitclass.java")); file.getparentfile().mkdirs(); pw = new printwriter(file); string line; int index = 0; while ((line = br.readline()) != null) { array[index] = line; index++; } } { checkmethods(); (int = 0; < array.length; i++) { system.out.println(array[i]); pw.println(array[i]); } br.close(); pw.flush(); pw.close(); } }
now returns:
public class dummybukkitclass extends javaplugin { @override public void onenable() { // profound code can found here } @override public void ondisable() { // profound code ending =( } }
i'm stumped why 1st 1 omitting 2 lines, while phone call right after there! able printed throughout adding process; , can print them before checkmethods() called. please help!
thanks you!
edit:
to prepare problem needed change:
else if (isoverride(array[i])) { if (checknextline(array[i++])) { array[i] = ""; } }
in checkmethods() to:
else if (isoverride(array[i])) { if (checknextline(array[i+1])) { //here array[i] = ""; } }
the reason behind this: increasing size of 'i' using 'i' 1 time again without resetting it. 'i+1' fixes because not setting new value i.
change checknextline(array[i++]) checknextline(array[i + 1]) or skip lines.
java arrays
No comments:
Post a Comment