Пожалуйста, мой apk работал нормально, принимая информацию о времени для медиа-песни, и неожиданно начал генерировать ошибку с переменной int в тот момент, когда он преобразует строковую переменную в int для вычисления времени в минутах и секундах.Вот эта ошибка¨
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.musicplayer, PID: 17390
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=1, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example.musicplayer/com.example.musicplayer.MainActivity}: java.lang.NumberFormatException: s == null
at android.app.ActivityThread.deliverResults(ActivityThread.java:5041)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5084)
at android.app.ActivityThread.-wrap20(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.NumberFormatException: s == null
at java.lang.Integer.parseInt(Integer.java:570)
at java.lang.Integer.parseInt(Integer.java:643)
at com.example.musicplayer.MainActivity.getSongTitle(MainActivity.java:655)
at com.example.musicplayer.MainActivity.onRequestPermissionsResult(MainActivity.java:689)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7854)
at android.app.Activity.dispatchActivityResult(Activity.java:7705)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5037)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5084)
at android.app.ActivityThread.-wrap20(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
I/Process: Sending signal. PID: 17390 SIG: 9
Application terminated.
код следующий:
public void getSongTitle() {
int Time1 = 0;
//retrieve song info
ContentResolver musicResolver = getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
if(musicCursor!=null && musicCursor.moveToFirst()){
//get columns
int titleColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ARTIST);
int timeColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.DURATION);
int time1Column = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.DURATION);
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisTime = musicCursor.getString(timeColumn);
String thisTime1 = ("");
Time1 = Integer.parseInt(thisTime)/1000;
double min = Math.floor(Time1/60);
double sec = (Time1 -min*60);
//thisTime1 = (""+min);
if (min<10) {
if (sec<10) {
thisTime1 =("0"+Math.round(min)+":0"+Math.round(sec));
}else{
thisTime1 =("0"+Math.round(min)+":"+Math.round(sec));
}
}else {
if (sec<10) {
thisTime1 =(""+Math.round(min)+":0"+Math.round(sec));
} else {
thisTime1 =(""+Math.round(min)+":"+Math.round(sec));
}
}
songList.add(new Song(thisId, thisTitle, thisArtist, thisTime, thisTime1));
}
while (musicCursor.moveToNext());
}
}
at com.example.musicplayer.MainActivity.getSongTitle(MainActivity.java:655)
ЕСТЬ ЛИНИЯ Time1 = Integer.parseInt(thisTime)/1000;
com.example.musicplayer.MainActivity.onRequestPermissionsResult(MainActivity.java:689) IS WHEN I CALL THE METHOD