오디오 플레이어 용 자습서는 this입니다. 서비스중인 노래를 재생할 수 있습니다.하지만 gson을 사용하여 노래를 저장하려고 시도하고 arraylist를 서비스에 보내지 만 내가 서비스gson 저장 데이터 및 미디어 플레이어 서비스를 사용하여 오류가 발생했습니다
FATAL EXCEPTION: main
Process: com.example.neelay.level95, PID: 15133
java.lang.RuntimeException: Unable to start service [email protected] with Intent { cmp=com.example.neelay.level95/.MediaPlayerService }: java.lang.RuntimeException: Failed to invoke private android.net.Uri() with no args
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3034)
at android.app.ActivityThread.access$2200(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Caused by: java.lang.RuntimeException: Failed to invoke private android.net.Uri() with no args
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:111)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:210)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:852)
at com.google.gson.Gson.fromJson(Gson.java:801)
at com.example.neelay.level95.StorageUtil.loadAudio(StorageUtil.java:42)
at com.example.neelay.level95.MediaPlayerService.onStartCommand(MediaPlayerService.java:106)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3017)
at android.app.ActivityThread.access$2200(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Caused by: java.lang.InstantiationException: Can't instantiate abstract class android.net.Uri
at java.lang.reflect.Constructor.newInstance(Native Method)
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:108)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:210)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:852)
at com.google.gson.Gson.fromJson(Gson.java:801)
at com.example.neelay.level95.StorageUtil.loadAudio(StorageUtil.java:42)
at com.example.neelay.level95.MediaPlayerService.onStartCommand(MediaPlayerService.java:106)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3017)
at android.app.ActivityThread.access$2200(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
오류 오류 목록 항목에 응용 프로그램 충돌을 클릭 할 때 나는 오류
가 표시되는 경우 songutil 클래스에서 오류를@Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
//Load data from SharedPreferences
StorageUtil storage = new StorageUtil(getApplicationContext());
audioList = storage.loadAudio();
audioIndex = storage.loadAudioIndex();
if (audioIndex != -1 && audioIndex < audioList.size()) {
//index is in a valid range
activeAudio = audioList.get(audioIndex);
} else {
stopSelf();
}
} catch (NullPointerException e) {
stopSelf();
}
//Request audio focus
if (requestAudioFocus() == false) {
//Could not gain focus
stopSelf();
}
if (mediaSessionManager == null) {
try {
initMediaSession();
initMediaPlayer();
} catch (RemoteException e) {
e.printStackTrace();
stopSelf();
}
buildNotification(PlaybackStatus.PLAYING);
}
//Handle Intent action from MediaSession.TransportControls
handleIncomingActions(intent);
return super.onStartCommand(intent, flags, startId);
}
오류를 얻고 곳
public ArrayList<Songfileinfo> loadAudio() {
preferences = context.getSharedPreferences(STORAGE, Context.MODE_PRIVATE);
Gson gson = new Gson();
String json = preferences.getString("audioArrayList", null);
Type type = new TypeToken<ArrayList<Songfileinfo>>() {
}.getType();
return gson.fromJson(json, type);
}
나는 내가 라인 (106) audioList = storage.loadAudio();
에서 라인 (41) return gson.fromJson(json, type);
에서 songutil 클래스에서 서비스 클래스에 오류가 발생하고 있음을 알에만 수 있어요하지만이 해결할 수있는 방법 어떤 도움 나가 수 있어요 helpfull.Now 될 것입니다 songfileinfo에서 코드를 제거하면 노래가 재생됩니다. 코드는
public class Songfileinfo implements Serializable {
private String title,album,artist,file_uri;
// 개인 Uri album_art입니다. // 개인 긴 기간;
public Songfileinfo(String data, String title, String album, String artist) {
this.file_uri = data;
this.title = title;
this.album = album;
this.artist = artist;
}
public Songfileinfo() {
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAlbum() {
return album;
}
public void setAlbum(String album) {
this.album = album;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getFile_uri() {
return file_uri;
}
public void setFile_uri(String file_uri) {
this.file_uri = file_uri;
}
}
을하지만 난 코드의 살전의 lises를 추가 할 때 여전히
private Uri album_art;
private long duration;
public Uri getAlbum_art() {
return album_art;
}
public void setAlbum_art(Uri album_art) {
this.album_art = album_art;
}
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
this.duration = duration;
}
가 나는 또한 생성자에서 추가 추락지고 y를 어떤 이유로 추락지고 있습니다.
튜토리얼을 보면 u가 여기에 저장된다는 것을 알 수 있습니다. 배열 우선 순위가 공동 배열 –
예.하지만 그들은 gson bro를 사용하여 "Uri"를 저장하지 않습니다. 데이터 객체 안에는 Uri 클래스가 없어야합니다. –