我正在使用2条件if语句
我想要if(一个整数== 0&&一个字符串!= null)
以下是代码:
int Coefficient = 0;
String Selection = null;
if(Coefficient == 0 && Selection != null ){
我的代码中的其他地方这种情况确实有效:
if(Selection == null){
System.out.println("No Data");
JOptionPane.showMessageDialog(null,"No Data Selected");
Selection字符串也来自“JComboBox” Selection =(String)SelectionComboBox.getSelectedItem();
if(Coefficient == 0&& Selection!= null){
我收到了.NullPointerException
我知道 if(Coefficient == 0)
本身就把我弄错了
我试过了
if(Coefficient == 0 && !Selection.equals(null) ){
if(Coefficient == 0 & Selection.equals(null) ){
if(Coefficient == 0 && Selection != null ){
if(Coefficient == 0 && !Selection.isEmpty()){
都会出现同样的错误
这里的代码我希望完整到足以“编译”并演示:
int Coefficient = 0;
String Selection = null;
System.out.printf("Source = %s\n",Selection);
if(Coefficient == 0 && Selection != null ){
System.out.printf(" HERE Selection = %s\n",Selection);
}
private void SelectionComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Selection = (String)SelectionComboBox.getSelectedItem();
}
if之外的printf给出“Selection = null” 这在线程“AWT-EventQueue-0”中给出了异常java.lang.NullPointerException
我正在使用NetBeans,我发现了一些“提示”或其他一些读取Invert If的内容 - 这有帮助吗?
帮助?
由于