How to solve NullPointerException error in Android?

后端 未结 3 549
时光说笑
时光说笑 2020-12-02 02:15

The below code runs smoothly in the emulator from Eclipse, but there are problems when I run it on my Android phone and tablet.

public class RingerActivity e         


        
相关标签:
3条回答
  • 2020-12-02 02:52

    Did you try cleaning the project ?? Newly added resources show up in the package explorer only after cleaning the project.

    0 讨论(0)
  • 2020-12-02 02:54

    NullPointerException, cause when there is no instance or array to use, the best to trace is to put breakpoint and debug your code.

    Seem your code is perfect, just make sure whether .mp3 is exist or not? and you perfectly kept inside raw folder.

    At last try to uninstall your existing and then clean your project and run. good luck.

    0 讨论(0)
  • 2020-12-02 02:56

    NullPointerException means that mp is null. This means the MediaPlayer.create() failed. Does R.raw.alarm exist?

    0 讨论(0)
提交回复
热议问题