بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
مشکل از کد ;()connection.connect
سلام
من در این پروژه از کلاس های خود استاد استفاده کردم از دو کلاس DownloadManeger و DownloadRequest اما متاسفانه عکس دانلود نمیشه من فکر کنم مشکل از کد ;()connection.connect این کد اجرا نمیشه و بقیه کدهای بعد از اون هم اجر نمیشن و مثل return عمل می کنه. THIS 1 در log cat نمایش داده میشه اما THIS 2 نمایش داده نمیشه.من سورس پروژه می ذارم تا بیشتر در جریان باشید
public class DownloadRequest {
private int downloadedSize;
private int totalSize;
private int percent;
public int getDownloadedSize() {
return downloadedSize;
}
public int getTotalSize() {
return totalSize;
}
public int getPercent() {
return percent;
}
public DownloadRequest download() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL(downloadPath);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
Log.i(G.LOG_CAT, "THIS 1");
connection.connect();
Log.i(G.LOG_CAT, "THIS 2");
totalSize = connection.getContentLength();
File file = new File(filepath);
if (file.exists()) {
file.delete();
}
FileOutputStream outputStream = new FileOutputStream(filepath);
InputStream inputStream = connection.getInputStream();
byte[] buffer = new byte[G.DOWNLOAD_BUFFER_SIZE];
int len = 0;
while ((len = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
downloadedSize += len;
percent = (int) (100.0f * (float) downloadedSize / totalSize);
if (percent == 100 && listener != null) {
G.HANDLER.post(new Runnable() {
@Override
public void run() {
listener.onCompleteLisnter(downloadPath, filepath);
}
});
}
if (simulate) {
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
outputStream.close();
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
});
thread.start();
return this;
}
private String downloadPath;
private String filepath;
private onCompleteDownloadLisnter listener;
private boolean simulate;
public DownloadRequest downloadPath(String value) {
downloadPath = value;
return this;
}
public DownloadRequest filepath(String value) {
filepath = value;
return this;
}
public DownloadRequest listener(onCompleteDownloadLisnter value) {
listener = value;
return this;
}
public DownloadRequest simulate(boolean value) {
simulate = value;
return this;
}
}
0
0
کد های نارنجی رنگ در logcat هم بزارید (10 سال پیش)
برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال
mohammadkhani
10 سال پیش
0
0
ممنون از پیگیر بودنتون
03-25 05:20:12.043: W/System.err(8402): org.json.JSONException: Value at 20 is null.
03-25 05:20:12.053: W/System.err(8402): at org.json.JSONArray.get(JSONArray.java:259)
03-25 05:20:12.053: W/System.err(8402): at org.json.JSONArray.getJSONObject(JSONArray.java:480)
03-25 05:20:12.053: W/System.err(8402): at com.uncocoder.app.coures.android.Commands.read(Commands.java:37)
03-25 05:20:12.053: W/System.err(8402): at com.uncocoder.app.coures.android.ActivityMain.onCreate(ActivityMain.java:31)
03-25 05:20:12.053: W/System.err(8402): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-25 05:20:12.053: W/System.err(8402): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-25 05:20:12.053: W/System.err(8402): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-25 05:20:12.053: W/System.err(8402): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-25 05:20:12.053: W/System.err(8402): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-25 05:20:12.053: W/System.err(8402): at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 05:20:12.053: W/System.err(8402): at android.os.Looper.loop(Looper.java:123)
03-25 05:20:12.053: W/System.err(8402): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-25 05:20:12.053: W/System.err(8402): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 05:20:12.053: W/System.err(8402): at java.lang.reflect.Method.invoke(Method.java:521)
03-25 05:20:12.053: W/System.err(8402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-25 05:20:12.053: W/System.err(8402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-25 05:20:12.053: W/System.err(8402): at dalvik.system.NativeStart.main(Native Method)
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .