我有一个mp3下载应用程序的源代码,几个月前我上次使用它时工作正常。现在,当我尝试它时,当我从搜索结果中点击一首歌来下载它时,它会给我一个错误。这是错误:
08-01 13:06:09.227: E/AndroidRuntime(2075): FATAL EXCEPTION: main
08-01 13:06:09.227: E/AndroidRuntime(2075): Process: com.soundload, PID: 2075
08-01 13:06:09.227: E/AndroidRuntime(2075): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Boolean de.voidplus.soundcloud.Track.isStreamable()' on a null object reference
08-01 13:06:09.227: E/AndroidRuntime(2075): at com.baixavideos.Downloader.onPostExecute(Downloader.java:41)
08-01 13:06:09.227: E/AndroidRuntime(2075): at com.baixavideos.Downloader.onPostExecute(Downloader.java:1)
08-01 13:06:09.227: E/AndroidRuntime(2075): at android.os.AsyncTask.finish(AsyncTask.java:636)
08-01 13:06:09.227: E/AndroidRuntime(2075): at android.os.AsyncTask.access$500(AsyncTask.java:177)
08-01 13:06:09.227: E/AndroidRuntime(2075): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
08-01 13:06:09.227: E/AndroidRuntime(2075): at android.os.Handler.dispatchMessage(Handler.java:102)
08-01 13:06:09.227: E/AndroidRuntime(2075): at android.os.Looper.loop(Looper.java:135)
08-01 13:06:09.227: E/AndroidRuntime(2075): at android.app.ActivityThread.main(ActivityThread.java:5254)
08-01 13:06:09.227: E/AndroidRuntime(2075): at java.lang.reflect.Method.invoke(Native Method)
08-01 13:06:09.227: E/AndroidRuntime(2075): at java.lang.reflect.Method.invoke(Method.java:372)
08-01 13:06:09.227: E/AndroidRuntime(2075): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
08-01 13:06:09.227: E/AndroidRuntime(2075): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
08-01 13:06:11.353: W/System.err(2174): java.io.IOException: open failed: EACCES (Permission denied)
08-01 13:06:11.353: W/System.err(2174): at java.io.File.createNewFile(File.java:941)
08-01 13:06:11.354: W/System.err(2174): at de.voidplus.soundcloud.SoundCloud.<init>(Unknown Source)
08-01 13:06:11.354: W/System.err(2174): at com.baixavideos.ui.MainActivity.<clinit>(MainActivity.java:63)
08-01 13:06:11.354: W/System.err(2174): at java.lang.reflect.Constructor.newInstance(Native Method)
08-01 13:06:11.354: W/System.err(2174): at java.lang.Class.newInstance(Class.java:1606)
08-01 13:06:11.354: W/System.err(2174): at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
Downloader.java:
package com.baixavideos;
import com.baixavideos.ui.SongDetails;
import de.voidplus.soundcloud.SoundCloud;
import de.voidplus.soundcloud.Track;
import android.os.AsyncTask;
import android.util.Log;
public class Downloader extends AsyncTask<String, Void, Track>{
private int id;
private SoundCloud soundcloud;
private SongDetails ui;
public Downloader(){
soundcloud = new SoundCloud("cd07b57592f6d914f437f8ab2856363d", "841953bd718a3ceb427b3e3be170a014");
}
public int getId() {
return id;
}
public Downloader setId(int id) {
this.id = id;
return this;
}
@Override
protected Track doInBackground(String... arg0) {
Track track = soundcloud.getTrack(getId());
return track;
}
@Override
protected void onPostExecute(Track track) {
super.onPostExecute(track);
if(track.isStreamable()){
getUi().onSongLoaded(track);
} else {
getUi().onStreamingError();
}
}
public SongDetails getUi() {
return ui;
}
public Downloader setUi(SongDetails ui) {
this.ui = ui;
return this;
}
}
答案 0 :(得分:1)
原因是你已经设置为Downloader的id(或者可能根本没有设置id)是错误的,并且在soundcloud
中没有具有这种id的轨道。 track
变量无法初始化并保持为空
它之前工作的原因是,那时你使用的是有效的曲目ID