Most of the carbonate formation are highly heterogeneous with cavities of different sizes, which makes the prediction of cavity-filled reservoir in carbonate rocks difficult. Large cavities in carbonate formations pose serious threat to drilling operations. Logging-whiledrilling (LWD) is currently used to accurately identify and evaluate cavities in reservoirs during drilling. In this study, we use the self-adaptive hp-FEM algorithm simulate and calculate the LWD resistivity responses of fracture-cavity reservoir cavities. Compared with the traditional h-FEM method, the self-adaptive hp-FEM algorithm has the characteristics of the self-adaptive mesh refinement and the calculations exponentially converge to highly accurate solutions. Using numerical simulations, we investigated the effect of the cavity size, distance between cavity and borehole, and transmitted frequency on the LWD resistivity response. Based on the results, a method for recognizing cavities is proposed. This research can provide the theoretical basis for the accurate identification and quantitative evaluation of various carbonate reservoirs with cavities encountered in practice.