Cov txheej txheem:

Vim li cas NullPointerException yog ib qho kev zam tsis tau txheeb xyuas?
Vim li cas NullPointerException yog ib qho kev zam tsis tau txheeb xyuas?

Video: Vim li cas NullPointerException yog ib qho kev zam tsis tau txheeb xyuas?

Video: Vim li cas NullPointerException yog ib qho kev zam tsis tau txheeb xyuas?
Video: Maa Vue - 'Lub Hli Puag Lub Hnub' (Official Music Video) 2024, Kaum ib hlis
Anonim

Java NullPointerException yog ib unchecked kev zam thiab ncua RuntimeException. NullPointerException tsis yuam peb siv catch block los lis nws. Qhov no kev zam yog zoo li npau suav phem rau feem ntau ntawm java developer zej zog. Lawv feem ntau tshwm sim thaum peb tsawg kawg xav tau lawv.

Ib yam li ntawd, nws raug nug, NullPointerException txhais li cas?

NullPointerException yog RuntimeException. Hauv Java, tus nqi tshwj xeeb null tuaj yeem raug xa mus rau qhov khoom siv. NullPointerException yog pov tseg thaum daim ntawv thov sim siv cov khoom siv uas muaj tus nqi null. Cov no suav nrog: Hu rau tus qauv piv txwv ntawm cov khoom xa los ntawm kev siv tsis raug.

Kuj Paub, dab tsi yog qhov kev zam tsis raug kuaj xyuas? Unchecked Exception hauv Java yog cov Kev zam uas tuav tsis tau txheeb xyuas lub sij hawm Compile. Cov no kev zam tshwm sim vim qhov programming phem. Qhov kev zov me nyuam yuav tsis muab qhov yuam kev muab tso ua ke. Tag nrho Unchecked kev zam yog cov chav kawm ncaj qha ntawm RuntimeException chav kawm.

Kuj kom paub, Kuv yuav kho qhov kev zam qhov tsis suav qhov pointer li cas?

Cov no suav nrog:

  1. Hu rau txoj kev piv txwv ntawm ib qho khoom tsis raug.
  2. Nkag mus lossis hloov kho qhov chaw ntawm ib qho khoom tsis raug.
  3. Noj qhov ntev ntawm null zoo li nws yog ib qho array.
  4. Kev nkag los yog hloov kho cov slots ntawm null zoo li nws yog ib qho array.
  5. Pov tseg null zoo li nws yog tus nqi Throwable.

Dab tsi yog qhov txawv ntawm ib qho kev kuaj xyuas thiab qhov tsis tau kuaj xyuas?

Lub ntsiab qhov sib txawv ntawm kev kuaj xyuas thiab unchecked kev zam yog tus kuaj xyuas kev zam yog kuaj ntawm compile-lub sij hawm thaum unchecked kev zam yog kuaj ntawm runtime.

Pom zoo: