Kev zam puas yuav ntes nullpointerexception?

Cov txheej txheem:

Kev zam puas yuav ntes nullpointerexception?
Kev zam puas yuav ntes nullpointerexception?
Anonim

Raws li tau hais nyob rau hauv lwm lo lus teb nws tsis pom zoo kom ntes NullPointerException. Txawm li cas los xij koj yeej yuav ntes tau, zoo li cov piv txwv hauv qab no qhia. Txawm hais tias NPE tuaj yeem ntes tau koj yuav tsum tsis txhob ua qhov ntawd tab sis kho qhov teeb meem pib, uas yog txoj hauv kev Check_Circular.

Puas NullPointerException yog ib qho kev kuaj xyuas?

Teb: NullPointerException tsis yog qhov kev kuaj xyuas. Nws yog ib tug xeeb leej xeeb ntxwv ntawm RuntimeException thiab yog unchecked.

Thaum twg qhov NullPointerException yuav raug pov tseg?

Ib qho kev zam tus taw qhia tsis tau raug pov tseg thaum daim ntawv thov sim siv null nyob rau hauv rooj plaub qhov twg yuav tsum muaj khoom. Cov no suav nrog: Hu rau tus qauv piv txwv ntawm ib qho khoom tsis raug. Nkag mus lossis hloov kho qhov chaw ntawm qhov khoom tsis raug.

Puas muaj kev zam txim rau txhua qhov kev zam?

Vim Kev Zam yog lub hauv paus ntawm txhua qhov kev zam, nws yuav ntes txhua qhov kev zam.

Vim li cas koj thiaj tsis ntes tau kev zam?

catch(Exception) yog kev coj tsis zoo vim nws ntes txhua yam RuntimeException (tsis txheeb xyuas) ib yam nkaus. Qhov no tej zaum yuav yog java tshwj xeeb: Qee zaum koj yuav tau hu rau txoj hauv kev uas cuam tshuam cov kev zam. Yog tias qhov no yog nyob rau hauv koj EJB / kev lag luam logic txheej koj muaj 2 txoj kev xaiv - ntes lawv lossis rov muab pov rau lawv.

Pom zoo: