Results 1 to 3 of 3
- 02-17-2011, 02:28 PM #1
Member
- Join Date
- May 2010
- Posts
- 17
- Rep Power
- 0
Array index out of range: 1 HELP!
i cant find out what im doing wrong!
Java Code:import java.util.LinkedList; import java.util.List; import java.util.Scanner; import java.util.Stack; public class Compiler { static int j,i = 0; static String CI; //CommandInput static Scanner I = new Scanner(System.in); //demanded Input static Stack M = new Stack(); //memory static int Mindex = 0; static int[][] O; //output (8x8 screen) static String ScopeVar , ScopeOp; static int ScopeVal; public static void main(String[] args) { CI = I.next(); M.push(0); while(i !=CI.length()) { CheckOps(i); CheckArgs(i); CheckVals(i); i++; } } public static int CheckOps(int a) { int SKIP = 0; int cv; if(CI.charAt(i) == ' '){SKIP = 1;} else if(CI.charAt(i) == '+') { cv = Integer.parseInt((M.get(Mindex)).toString()); M.set(Mindex,cv+1); }else if(CI.charAt(i) == '-') { cv = Integer.parseInt((M.get(Mindex)).toString()); M.set(Mindex,cv-1); }else if(CI.charAt(i) == '!') { System.out.printf("%d",M.pop()); }else if(CI.charAt(i) == '>') { Mindex+=1; if(Mindex > M.size()) { M.push(0); } }else if(CI.charAt(i) == '<') { Mindex-=1; if(!(Mindex <1)) { M.add(Mindex,0); } } return(SKIP); } public static void CheckArgs(int a) { } public static void CheckVals(int a) { } }Java Code:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1 at java.util.Vector.get(Unknown Source) at Compiler.CheckOps(Compiler.java:37) at Compiler.main(Compiler.java:22)
- 02-17-2011, 03:22 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,589
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-17-2011, 08:50 PM #3
Member
- Join Date
- May 2010
- Posts
- 17
- Rep Power
- 0
Similar Threads
-
java.sql.SQLException: Column Index out of range, 3 > 1.
By chathura992 in forum JDBCReplies: 2Last Post: 01-07-2011, 11:50 AM -
String index out of range: -1 Please Help
By davetheant in forum New To JavaReplies: 22Last Post: 09-11-2010, 12:32 AM -
Range within an Array
By End in forum New To JavaReplies: 6Last Post: 04-18-2009, 06:53 PM -
Array Index problems
By ragnor2004 in forum New To JavaReplies: 4Last Post: 03-26-2009, 07:53 PM -
Writing integer pixel array(Range:0-255) into .txt file
By Mazharul in forum Java 2DReplies: 3Last Post: 08-24-2008, 01:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks