رفتن به مطلب
  • 0

لغو دانلود


reza644

سوال

سلام

مشل من اینه وقتی فایل دانلود میشه موقع خروج سرویسstop HttpUtils2Service  میکنم موقع (دانلود اسم دکمش dw هست) همون سرویس رو start میکنم ولی ارور میده 

توی حالت release:میگه آبجکت باید اینیشیالایز شه

توی حالت debug :

خط خاصی رو نشون نمیده

و اینو مینویسه


java.lang.RuntimeException: java.lang.NullPointerException: Attempt to write to field 'boolean anywheresoftware.b4a.samples.httputils2.httpjob._success' on a null object reference
	at anywheresoftware.b4a.BA.raiseEvent2(BA.java:206)
	at anywheresoftware.b4a.BA$2.run(BA.java:328)
	at android.os.Handler.handleCallback(Handler.java:743)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:150)
	at android.app.ActivityThread.main(ActivityThread.java:5546)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)
Caused by: java.lang.NullPointerException: Attempt to write to field 'boolean anywheresoftware.b4a.samples.httputils2.httpjob._success' on a null object reference
	at anywheresoftware.b4a.samples.httputils2.httputils2service._completejob(httputils2service.java:99)
	at anywheresoftware.b4a.samples.httputils2.httputils2service._response_streamfinish(httputils2service.java:152)
	at java.lang.reflect.Method.invoke(Native Method)
	at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
	... 8 more
#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: false
#End Region
  																		  

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
Dim hj As HttpJob
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
Dim lbl As Label
Dim lpic As Label
Dim awake As PhoneWakeState
    Dim link,name,dier As String
    Dim mediaplayer1 As MediaPlayer
	Dim lname As Label
	Dim lurl As Label
Dim fara As Farakhani
	Private ScrollView1 As ScrollView
'	Private  As Button
'	Private  As Button
	Dim l As Label
'	Dim cafe As Intent
	Dim ts As TextSetting
	Private dw As Button
	Private st As Button
	Private pu As Button
	Private pl As Button
	Private imageview1 As ImageView
	Private pl2 As Button
	Dim m2 As m2Lib
		Dim no As Notification
	Dim tite2 As String
	Dim tite1 As Label
	Private Label1 As Label
	Dim h As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("download")

File.MakeDir(File.DirRootExternal, "kodack")
tite1.Initialize("")
lname.Initialize("")
lurl.Initialize("")
dw.Visible=True
pl.Visible=False
pu.Visible=False
st.Visible=False
pl2.Visible=False
h=0
lbl.Initialize("")
l.Initialize("")
lpic.Initialize("")	
ts.Initialize

lbl.TextColor=Colors.Black
lbl.Typeface=Typeface.LoadFromAssets("Far_KoodkBd.ttf")
Label1.Typeface=Typeface.LoadFromAssets("Far_KoodkBd.ttf")
dw.Typeface=Typeface.LoadFromAssets("Far_KoodkBd.ttf")
pl.Typeface=Typeface.LoadFromAssets("Far_KoodkBd.ttf")
pu.Typeface=Typeface.LoadFromAssets("Far_KoodkBd.ttf")
st.Typeface=Typeface.LoadFromAssets("Far_KoodkBd.ttf")
pl2.Typeface=Typeface.LoadFromAssets("Far_KoodkBd.ttf")
		
	If(File.Exists(File.DirRootExternal,"c.txt")) Then 
		
	Dim str As String
str = File.readString(File.DirRootExternal,"c"&".txt")
If str = "Colors.Black" Then
lbl.textColor = Colors.Black
Else If str = "Colors.Red" Then
lbl.textColor = Colors.Red
Else If str = "Colors.Blue" Then
lbl.textColor = Colors.Blue
End If
Else
lbl.textColor = Colors.Black		
	End If


fara.FarakhaniMatn("kodack.db",Main.sql1,Main.cur,"SELECT * FROM ghese1 where id=",ghese.meghdar,tite1,"titr")
fara.FarakhaniMatn("kodack.db",Main.sql1,Main.cur,"SELECT * FROM ghese1 where id=",ghese.meghdar,lbl,"matn")
fara.FarakhaniMatn("kodack.db",Main.sql1,Main.cur,"SELECT * FROM ghese1 where id=",ghese.meghdar,lname,"name")
fara.FarakhaniMatn("kodack.db",Main.sql1,Main.cur,"SELECT * FROM ghese1 where id=",ghese.meghdar,lurl,"url")
fara.FarakhaniMatn("kodack.db",Main.sql1,Main.cur,"SELECT * FROM ghese1 where id=",ghese.meghdar,lpic,"pic2")
tite2=tite1.Text		
'		lbl.Textsize=File.GetText(File.DirRootExternal,"textsize"&".txt")
'		l.Text=File.GetText(File.DirRootExternal,"textsize"&".txt")
	imageview1.SetBackgroundImage(LoadBitmap(File.DirAssets,lpic.Text))

	imageview1.Height=m2.GetPicHeight(imageview1)
	imageview1.Width=m2.GetPicWidth(imageview1)
			If(File.Exists(File.DirRootExternal & "/kodack", lname.Text)) Then 
				
	 ToastMessageShow("نیازی به دانلود نیست",  True)
	
	mediaplayer1.Initialize2("mediaplayer1")
mediaplayer1.Load(File.DirRootExternal & "/kodack", lname.Text)
    mediaplayer1.Looping=False

dw.Visible=False
pl.Visible=True
pu.Visible=False
st.Visible=True
pl2.Visible=False	
Label1.Visible=False			
Else
Label1.Visible=False


	End If

			If(File.Exists(File.DirRootExternal,"s.txt")) Then 
'		lbl.Textsize=File.GetText(File.DirRootExternal,"textsize"&".txt")
'		l.Text=File.GetText(File.DirRootExternal,"textsize"&".txt")
		
		Main.cur.Position = 0
		
ScrollView1.Panel.AddView(lbl,0,0,75.5%x,100%y)
ts.LongText(lbl,lbl.Text,File.GetText(File.DirRootExternal,"s"&".txt"),ScrollView1,1.5)
Else
ScrollView1.Panel.AddView(lbl,0,0,75.5%x,100%y)
ts.LongText(lbl,lbl.Text,18,ScrollView1,1.5)

	End If

	lbl.Gravity=Gravity.RIGHT

	mediaplayer1.Initialize2("mediaplayer1")


awake.KeepAlive(True)
End Sub

Sub JobDone(Job As HttpJob) 

	Try                            
If Job.Success = True Then
Select Case Job.JobName
  Case "job1"
  Dim o As OutputStream
  o = File.OpenOutput(dier, name, False)
    File.Copy2(Job.GetInputStream, o)
    o.Close
    Job.Release
    Case "job2"
    Dim o As OutputStream
  o = File.OpenOutput(dier, name, False)
    File.Copy2(Job.GetInputStream, o)
    o.Close
    Job.Release
    ToastMessageShow("دانلود شد!",True)
	Label1.Visible=False

h=0
    Case "job3"
    Dim o As OutputStream
  o = File.OpenOutput(dier, name, False)
    File.Copy2(Job.GetInputStream, o)
    o.Close
    Job.Release

h=0
    ToastMessageShow("دانلود شد!",True)
	Label1.Visible=False
dw.Visible=False
pl.Visible=False
pl2.Visible=True
 End Select
 Else
 h=0	
Msgbox("اول باید به یه اینترنت سریع وصل شی...","ببخشید!!!")
dw.Visible=True
pl.Visible=False
pl2.Visible=False	
Label1.Visible=False

End If
ProgressDialogHide
Catch
If(File.Exists(File.DirRootExternal & "/kodack", lname.Text)) Then
	File.Delete(File.DirRootExternal & "/kodack", lname.Text)
	
	
	End If	
dw.Visible=True
pl.Visible=False
pl2.Visible=False	
Label1.Visible=False
	
	
 Dim r As Int         
    r = Msgbox2("خطایی رخ داده...","","لغو","","دوباره",LoadBitmap(File.DirAssets,"icon.png"))        
    If ( r = DialogResponse.POSITIVE) Then 
   Activity.Finish


 h=0
    End If
    If ( r = DialogResponse.NEGATIVE) Then 


dw.Visible=True
pl.Visible=False

name=lname.Text
dier=File.DirRootExternal& "/kodack"
link=lurl.Text
hj.Initialize("job3",Me)
hj.Download(link)

 h=1


Label1.Visible=True
dw.Visible=False



 

End If
	
	End Try
End Sub
Sub Activity_Pause (UserClosed As Boolean)


StopService(HttpUtils2Service)
End Sub
Sub dw_Click
StartService(HttpUtils2Service)

dw.Visible=True
pl.Visible=False
h=1
name=lname.Text
dier=File.DirRootExternal& "/kodack"
link=lurl.Text
hj.Initialize("job3",Me)
hj.Download(link)




Label1.Visible=True
dw.Visible=False



 
End Sub
Sub pl_click
mediaplayer1.Load(File.DirRootExternal & "/kodack", lname.text)
mediaplayer1.Play
dw.Visible=False
pl.Visible=False
pu.Visible=True
st.Visible=True
pl2.Visible=False
h=2
no.Initialize
no.Icon="icon"
no.Light=True
no.Vibrate = False
no.sound = False
no.AutoCancel=False
no.OnGoingEvent=True
no.SetInfo("درحال پخش...",tite2,Null)
no.AutoCancel=True
no.Cancel(1)
no.Notify(1)
End Sub
Sub pu_click
mediaplayer1.Pause
dw.Visible=False
pl.Visible=False
pu.Visible=False
st.Visible=True
pl2.Visible=True
h=0
no.Cancel(1)
End Sub
Sub st_click
mediaplayer1.Stop
dw.Visible=False
pl.Visible=True
pu.Visible=False
st.Visible=True
pl2.Visible=False
h=0
no.Cancel(1)
End Sub
Sub pl2_click
mediaplayer1.Play
dw.Visible=False
pl.Visible=False
pu.Visible=True
st.Visible=True
pl2.Visible=False
h=2
no.Initialize
no.Icon="icon"
no.Light=True
no.Vibrate = False
no.sound = False
no.AutoCancel=True
no.OnGoingEvent=True
no.SetInfo("درحال پخش...",tite2,Null)
no.AutoCancel=True

no.Notify(1)
End Sub
Sub mediaplayer1_Complete
dw.Visible=False
pl.Visible=True
pu.Visible=False
st.Visible=True
pl2.Visible=False
h=0
no.Cancel(1)
End Sub



Sub Activity_Resume

End Sub
	

'Sub ImageView7_Click	
'	cafe.Initialize(cafe.ACTION_EDIT,"bazaar://details?id=com.sorod.pack") 
'	StartActivity(cafe) 
'End Sub



'Sub CreateUri(uri As String) As Object
'   Dim r As Reflector
'   Return r.RunStaticMethod("android.net.Uri", "parse", Array As Object(uri), Array As String("java.lang.String"))
'End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean
	
	If h=1 Then
    If KeyCode = KeyCodes.KEYCODE_BACK Then
 Dim r As Int         
    r = Msgbox2("دانلود لغو شه؟","","آره","","نه",LoadBitmap(File.DirAssets,"icon.png"))        
    If ( r = DialogResponse.POSITIVE) Then 


	StopService(HttpUtils2Service)
	Activity.Finish
	End If
	If KeyCode = KeyCodes.KEYCODE_BACK Then
Return True
	End If
	
    If ( r = DialogResponse.NEGATIVE) Then 
Return True
    End If
End If
End If

	






End Sub

نکته:من 18 تا module ساختم و اگه از سورس largfiledownload استفاده کنم خیلی وقت میبره.

نکته:وقتی دانلود رو لغو میکنم و دوباره برمیگردم که دانلود کنم این ارور رو میده

نکته:وقتی بعد ارور برمیگردم قسمت قبلی یه لیست ویو دارم که از دیتابیس متناشو فراخوانی میکنه که کاملا سفید میشه

توجه:من فقط میخوام دانلودم لغو شه اگه سرویسم متوقف نشد مهم نیست 

لینک ارسال
به اشتراک گذاری در سایت های دیگر

1 پاسخ به این سوال تاکنون داده شده است

ارسال‌های توصیه شده

بایگانی شده

این موضوع بایگانی و قفل شده و دیگر امکان ارسال پاسخ نیست.

  • کاربران آنلاین در این صفحه   0 کاربر

    • هیچ کاربر عضوی،در حال مشاهده این صفحه نیست.
×
×
  • اضافه کردن...