2010-12-15 47 views
-2

dBのデータがない場合はdbからデータを取得する必要があります。javaのポップアップウィンドウを起動する必要があります。私は処理するためにここにコードを書いていますが、それを処理することはできません。java例外処理

String SectorCode = employerProfile.getSectorCode().getSectorTypeId(); 
String IndustrialCode = employerProfile.getIndustrialCode().getIndustryTypeId(); 
try{ 
    if(SectorCode==null || IndustrialCode==null){ 
     JOptionPane.showMessageDialog(null, "Record not found"); 
    } 
}catch(Exception ex){ 
    ex.printStackTrace(); 
} 

あなたがあまりにも、空の文字列をチェックする必要があるかもしれません設定されているどのように使用するデータベースに応じて、および/または...私に事前

+0

だから、実際の問題は何ですか?それは例外を投げていますか?ダイアログボックスが表示されませんか? –

+0

はいthrowing exception ... dBのファイルが存在しないときにポップアップウィンドウを取得する必要があります。 – charan

+0

@charan ...この呼び出しが例外をスローすると...レコードが見つかりません。 。??私は...? – water

答えて

1

それを行う一つの厄介な方法は...(あなたがnullポインタ例外を取得していることを述べた)

String SectorCode = null; 
String IndustrialCode = null; 
try{ 
    SectorCode = employerProfile.getSectorCode().getSectorTypeId(); 
    IndustrialCode = employerProfile.getIndustrialCode().getIndustryTypeId(); 
    ... 
}catch(Exception ex){ 
    if(SectorCode==null || IndustrialCode==null){ 
     JOptionPane.showMessageDialog(null, "Record not found"); 
    } 
} 
0

で おかげで解決策を提案してください。

if(SectorCode==null || IndustrialCode==null || SectorCode.length() == 0 || IndustrialCode.length() == 0) { 
+0

こんにちはsjngm ...その動作しません。私はポップアップを取得していない... – charan

1

ifブロックが実行されない場合、最初の2行のメソッド呼び出しで例外が発生する可能性があることを意味します。 employerProfile.getSectorCode().getSectorTypeId();employerProfile.getIndustrialCode().getIndustryTypeId();の行が例外なく正しく実行されているかどうかを確認してください。

+0

いいえchaitanya。最初の2行に例外はありません。ブロックすると実行できません。 javaコンソールのfinalでnullポインタ例外を表示しています – charan

+0

あなたは正しいです。ブロックがtry-catchブロック内にあるため例外がなければブロックは実行されません。 –