是的,我知道這個錯誤比普通流感更常見,並且我也不知道如何解決它。因爲坦率地說,我不知道這個特殊情況下的含義。我有非常簡單的代碼來檢查括號,但它沒有編譯到此,我不知道爲什麼。錯誤:非靜態方法不能從靜態上下文中引用
的錯誤是在測試類,行14
但這裏有我的兩個,只有類。
import java.util.Stack;
import java.util.EmptyStackException;
class Arithmetic
{
Stack <Object>stk;
String expression;
int length;
Arithmetic(String s)
{
expression = s;
length = expression.length();
stk = new Stack<Object>();
}
boolean isBalanced()
{
int index = 0;
boolean fail = false;
try
{
while(index < length)
{
char ch = expression.charAt(index);
switch(ch)
{
case '(':
stk.push(ch);
break;
case ')':
stk.pop();
break;
default:
//ignore all others chars.
break;
}
index++; //increment index to continue on to the next char.
}
}
catch(EmptyStackException e)
{
fail = true;
}
return fail;
}
}
的一個出現錯誤:
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
class TestFile
{
public static void main(String[] arg)
{
String menu = "Please enter an arithmetic expression to evaluate for balance:";
String s = JOptionPane.showInputDialog(menu);
display(s);
new Arithmetic(s);
boolean balanced = Arithmetic.isBalanced();
display(balanced);
}
static void display(boolean Boolean)
{
JOptionPane.showMessageDialog(null, Boolean, "Content", JOptionPane.INFORMATION_MESSAGE);
}
static void display(String s)
{
JOptionPane.showMessageDialog(null, s, "Content", JOptionPane.INFORMATION_MESSAGE);
}
}
把你的頭轉向右邊,看看'Related'部分。 –
如果這會有所幫助,我會這樣做,但它只是讓我更困惑。 – user3236502
沒有任何人在這裏發佈將有助於。 –