私は2つの条件付きif文で打ちのめしています
if( an integer == 0 && a string != 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(係数 == 0 && 選択 != 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 を読み取る「ヒント」またはそのようなものに気付きました - これは役に立ちますか?
ヘルプ?
ありがとう