0

Setting Ringtone in Android

I have tried using this code, but I keep getting a nullpointedexception at

FileInputStream fis = soundFile.createInputStream();

I have added permissions, but the error is still there?

Community
  • 1
  • 1
bunbun
  • 2,595
  • 3
  • 34
  • 52

1 Answers1

0

if you code is the same as

try {
       soundFile= mCr.openAssetFileDescriptor(mUri, "r");
   } catch (FileNotFoundException e) {
       soundFile=null;   
   }
  try {
      byte[] readData = new byte[1024];
      FileInputStream fis = soundFile.createInputStream();

then what is probably happening is that

mCr.openAssetFileDescriptor(mUri, "r");

is either returning null or triggering an exception.

I would:

1) add some logs to trace exactly where the problem is

2) check that you have all the permissions

3) check that the file you are trying to open exist and is at the right location

if that fails come back here with some logs and we'll help more ;)

Jason Rogers
  • 19,194
  • 27
  • 79
  • 112