String index out of bounds exception java

You are calling str.substring(i, j-i) which means substring(beginIndex, endIndex), not substring(beginIndex, lengthOfNewString). One of assumption of this method is that endIndex is greater or equal beginIndex, if not length of new index will be negative and its value will be thrown in StringIndexOutOfBoundsException. Maybe you should change your method do something like str.substring(i, j)? Also if size is length of your str then should probably be

charAt error “char cannot be converted to string”

currLet = str.charAt(currPos); A String value can’t be assigned to a char, they are different types, apples and oranges if (currLet = str.charAt(currPos + 1)) { is actually an assignment (make currLet equal to the value of str.charAt(currPos + 1)) if (currLen > maxLen) { – maxLen is undefined You never return anything from the method… Try changing: String currLet = “”; to something more like char currLet = ‘\0’; and String … Read more

Error in Swift class: Property not initialized at super.init call

Quote from The Swift Programming Language, which answers your question: “Swift’s compiler performs four helpful safety-checks to make sure that two-phase initialization is completed without error:” Safety check 1 “A designated initializer must ensure that all of the “properties introduced by its class are initialized before it delegates up to a superclass initializer.” Excerpt From: … Read more