Results 1 to 2 of 2
  1. #1
    hiawathado is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Default soundpool dynamically loading null pointer exeption

    Hello,
    I have a soundpool class loading sounds from ArrayList of listst. First it loads fine, and I sounds are played. But when I change arrayList, It throuws exeption... any ideas why it could go wrong?

    Java Code:
    public static void loadSounds()
    {
        cleanup();
        initSounds(Startup_settings.getAppContext());
        File sdCard = Environment.getExternalStorageDirectory();
        int i2 = 100,i;
    
        for(int i1 = 1; i1<Settings.musicLists.size();i1++){ //begin bij 1, 0 is musiek
            List<Mp3> list = Settings.musicLists.get(i1);
            int k = i2;
            if(Settings.musicLists.get(i1).size()>0){
                for( i = 0; i < list.size(); i++){
    
                    mSoundPoolMap.put(k, mSoundPool.load(sdCard.getAbsolutePath() + 
                            "/music/"+list.get(i).toString(), 1));
                    k=k+i;
                }
            }
            i2=i2+100;
    
        }
    public static void cleanup()
    {
        mSoundPool.release();
        mSoundPool = null;
        mSoundPoolMap.clear();
        mAudioManager.unloadSoundEffects();
        _instance = null;
    
    }
    Java Code:
    public static void playSound(int index){
        Random rand = new Random();
        if(Settings.musicLists.get(index).size() > 0){
            playSoundIntern((index*100)+randInd,1);
                        int randInd = rand.nextInt(Settings.musicLists.get(index).size());
                }
    }
    private static void playSoundIntern(int index,float speed) 
    {       
             float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
             streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
             mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, speed); 
             if(D)Log.d("SoundManager","isPlaying: "+index);
    }
    LogCat:
    Java Code:
    03-16 06:19:38.749: D/AndroidRuntime(13333): Shutting down VM
    03-16 06:19:38.749: W/dalvikvm(13333): threadid=1: thread exiting with uncaught exception (group=0x40018578)
    03-16 06:19:38.769: E/AndroidRuntime(13333): FATAL EXCEPTION: main
    03-16 06:19:38.769: E/AndroidRuntime(13333): java.lang.NullPointerException
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at android.kvisio.inc.SoundManager.playSoundIntern(SoundManager.java:136)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at     android.kvisio.inc.SoundManager.playSound(SoundManager.java:130)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at  android.kvisio.Startup_settings$1.handleMessage(Startup_settings.java:171)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at android.os.Handler.dispatchMessage(Handler.java:99)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at android.os.Looper.loop(Looper.java:130)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    03-16 06:19:38.769: E/AndroidRuntime(13333):    at dalvik.system.NativeStart.main(Native Method)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,751
    Rep Power
    19

    Default Re: soundpool dynamically loading null pointer exeption

    What line is line 136?

    When cleanup() is called you set mSoundPool to null...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Getting a null pointer exception when loading my JSP result page
    By rc1138 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-13-2011, 02:23 PM
  2. Replies: 0
    Last Post: 10-01-2011, 04:14 AM
  3. null pointer exeption : how solve it ?
    By miki_ir in forum New To Java
    Replies: 11
    Last Post: 09-05-2011, 02:38 AM
  4. Null Pointer Exeption
    By Aldane in forum AWT / Swing
    Replies: 3
    Last Post: 03-19-2011, 10:11 AM
  5. null pointer exeption
    By mj23brm in forum New To Java
    Replies: 4
    Last Post: 02-10-2009, 11:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •