Some test case are give run time error in balanced paranthesis

this is my code what is problem in this code
public static boolean isBalanced(String s, StacksUsingArrays p) throws Exception {
for(int i=0;i<s.length();i++) {
if(s.charAt(i)==’(’||s.charAt(i)==’{’||s.charAt(i)==’[’){
p.push(s.charAt(i));
}else{
if(p.isEmpty())
return false;
if(s.charAt(i)==’)’ && p.top()!=’(’ ||
s.charAt(i)==’}’&&p.top()!=’{’||
s.charAt(i)==’]’&& p.top()!=’[’) {
return false;
}
p.pop();
}
}
return p.isEmpty();
}

@sksumitkumardiwaker,
Can you share the complete code? https://ide.codingblocks.com/

import java.util.*; public class Main { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); String str = s.next(); Main mainobj = new Main(); StacksUsingArrays stack = mainobj.new StacksUsingArrays(1000); if (isBalanced(str, stack)) { System.out.println(β€œYes”); } else { System.out.println(β€œNo”); } } public static boolean isBalanced(String s, StacksUsingArrays p) throws Exception { for(int i=0;i<s.length();i++) { if(s.charAt(i)==’(’||s.charAt(i)==’{’||s.charAt(i)==’[’){ p.push(s.charAt(i)); }else{ if(p.isEmpty()) return false; if(s.charAt(i)==’)’ && p.top()!=’(’ || s.charAt(i)==’}’&&p.top()!=’{’|| s.charAt(i)==’]’&& p.top()!=’[’) { return false; } p.pop(); } } return p.isEmpty(); } private class StacksUsingArrays { private int[] data; private int tos; public static final int DEFAULT_CAPACITY = 10; public StacksUsingArrays() throws Exception { // TODO Auto-generated constructor stub this(DEFAULT_CAPACITY); } public StacksUsingArrays(int capacity) throws Exception { if (capacity <= 0) { System.out.println(β€œInvalid Capacity”); } this.data = new int[capacity]; this.tos = -1; } public int size() { return this.tos + 1; } public boolean isEmpty() { if (this.size() == 0) { return true; } else { return false; } } public void push(int item) throws Exception { if (this.size() == this.data.length) { throw new Exception(β€œStack is Full”); } this.tos++; this.data[this.tos] = item; } public int pop() throws Exception { if (this.size() == 0) { throw new Exception(β€œStack is Empty”); } int retVal = this.data[this.tos]; this.data[this.tos] = 0; this.tos–; return retVal; } public int top() throws Exception { if (this.size() == 0) { throw new Exception(β€œStack is Empty”); } int retVal = this.data[this.tos]; return retVal; } public void display() throws Exception { if (this.size() == 0) { throw new Exception(β€œStack is Empty”); } for (int i = this.tos; i >= 0; i–) { System.out.println(this.data[i]); } } } }

sir question ho gaya