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

ارور java.lang.NullPointerException


ehsan20000

سوال

با سلام خدمت همه دوستان 

 

عزیزان من قبلا یک تایپک زدم ولی کسی جواب نداد

این تایپک رو حتما جواب بدین من این برنامه که لینکشو گذاشتم رو وقتی تو گوشی باز میکنم و در قسمت اهنگ ها مثلا اهنگ یک رو میخوام بزنم برای اهنگ زنگ اگه به جای بله خیر بزنم

 

java.lang.NullPointerException  اینو بهم میده

 

answercenter.ir/uploads/monthly_11_2015/post-4327-0-24421300-1448844891.jpg

 

لطفا نگاش کنین بگین چیکار کنم خیلی واجبه

 

سورس برنامه:

http://s3.picofile.com/file/8226029800/aaa.zip.html

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

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

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

سلام.

 

برادر کدهاتون رو قرار بدید تا بررسی کنیم.

اون همه آهنگ اضافه کردید کلی حجم سورسه کسی دانلود نمیکنه. اگه نیازی به سورس باشه حتما میگیم.

فعلا کدهاتون رو بذارید.

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

سلام.

 

برادر کدهاتون رو قرار بدید تا بررسی کنیم.

اون همه آهنگ اضافه کردید کلی حجم سورسه کسی دانلود نمیکنه. اگه نیازی به سورس باشه حتما میگیم.

فعلا کدهاتون رو بذارید.

 

اکتیوتی main

#Region  Project Attributes 
	#ApplicationLabel:  رینگتون
	#VersionCode: 1
	#VersionName: 1.0
	'SupportedOrientations possible values: unspecified, landscape or portrait.
	#SupportedOrientations: portrait
	#CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
	#FullScreen: True
	#IncludeTitle: False
#End Region

Sub Process_Globals
Dim Timer1 As Timer
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.
    
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("splash")
    Timer1.Initialize("Timer1",1000)
    Timer1.Enabled=True

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Timer1_tick
Timer1.Enabled=False
StartActivity("main1")
ToastMessageShow("خوش آمدید",False)
Activity.Finish
End Sub

main1


#Region  Activity Attributes 
	#FullScreen: True
	#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 TYPE_HELLO_WORLD As Int : TYPE_HELLO_WORLD = 1
	
	
	
	Dim TYPE_LISTVIEW1 As Int : TYPE_LISTVIEW1 = 2
	

	
	Dim TYPE_SETTINGS As Int : TYPE_SETTINGS = 3
	

	
	
	
	Dim FILL_PARENT As Int : FILL_PARENT = -1
	Dim WRAP_CONTENT As Int : WRAP_CONTENT = -2

	'We put this information to the panel tag of the panel for the pages
	Type PanelInfo (PanelType As Int, LayoutLoaded As Boolean) 

	Dim CurrentTheme As Int : CurrentTheme = 0
	Dim CurrentPage As Int : CurrentPage = 0

	Dim mp As Int
    Dim a As Int
	
	
	
	
	
	
	
	
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.
	
	'The container and the ViewPager objects
	Dim container As AHPageContainer
	Dim pager As AHViewPager
	'Optionally you can use an AHViewPagerTabs object as a page indicator
	Dim tabs As AHViewPagerTabs
	
	'This panel is just for a colored line between the tabs and the pages.
	Dim line As Panel

	'Button for direct page access
	Dim Button1 As Button
	
	Dim spTheme As Spinner


	
End Sub

Sub Activity_Create(FirstTime As Boolean)

	'Add a Button at the bottom of the page for jumping directly to a page.
	Button1.Initialize("Button1")
	Button1.Gravity = Gravity.CENTER
	Activity.AddView(Button1, 88dip, Activity.Height - 44dip, Activity.Width - 88dip - 88dip, 40dip)
	
	
	
	'Initialize the panels we use for the pages and put them in the container
	container.Initialize
	For i = 0 To 3
		Dim pan As Panel
		
		Select i
			Case 0
				
				pan = CreatePanel(TYPE_HELLO_WORLD, "خوش آمدید")
				container.AddPage(pan,"صفحه نخست ")
			
			Case 1
				pan = CreatePanel(TYPE_LISTVIEW1, "زیبا ")
				container.AddPage(pan,"زیبا ")
				
				
				Case 2
				
				pan = CreatePanel(TYPE_SETTINGS, "تنظیمات")
				container.AddPage(pan,"تنظیمات")
				
				
				
				
		End Select
	Next
	
	'Now we have a container with our panels just add it to the pager object
	pager.Initialize(container, "Pager")
	
	'As we want to show the tabs page indicator, we initialize it
	tabs.Initialize(pager)
	tabs.LineHeight = 5dip
	tabs.UpperCaseTitle = True
	Activity.AddView(tabs, 0, 0, FILL_PARENT, WRAP_CONTENT)
	
	'We add a line below the tab page indicator because it looks good
	Dim col As ColorDrawable
	col.Initialize(tabs.LineColorCenter, 0)
	line.Initialize("")
	line.Background=col
	Activity.AddView(line, 0, 35dip, Activity.Width, 2dip)
	
	'Now we can add the pager to the activity
	Activity.AddView(pager, 0, 35dip + 2dip, Activity.Width, Activity.Height-48dip-35dip-2dip)
	SetButtonText
	SetTheme(CurrentTheme)
	
	'Add some menus for adding and removing pages
	

	
	

	
End Sub

Sub Activity_Resume
	'Do not call this in Activity_Create since the initialization is not complete then!
	pager.GotoPage(CurrentPage, False)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

'This creates a page of the given type
Sub CreatePanel(PanelType As Int, Title As String) As Panel
	Dim pan As Panel
	Dim pi As PanelInfo
	
	pi.Initialize
	pi.LayoutLoaded = False
	pi.PanelType = PanelType

	pan.Initialize("")
	Select PanelType
		Case TYPE_HELLO_WORLD
		    pan.LoadLayout("meno")
		
	
		
		
		Case TYPE_LISTVIEW1
		
		
			Dim lv As ListView
			
			lv.Initialize("LV1")
			
			For i = 1 To 20
				lv.AddSingleLine(" زیبا " & i)
				
			Next
			
			pan.AddView(lv, 0, 0, FILL_PARENT, FILL_PARENT)
					
				Dim itbg  As BitmapDrawable
	            itbg.Initialize(LoadBitmap(File.DirAssets,"bac1.png"))
					lv.Background=itbg
				lv.SingleLineLayout.Label.TextColor=Colors.White
				lv.SingleLineLayout.Label.TextSize=20
					
			
			
	End Select 
	
	pan.Tag = pi
	Return pan
End Sub

Sub NewPage_Click
	Dim names As List
	Dim ret As Int
	
	names.Initialize
	names.Add("سلام")
	names.Add("تنظیمات")
	names.Add("رینگتون")
	
	ret = InputList(names, "Choose page type", -1)
	
	If ret = DialogResponse.CANCEL Then
		ToastMessageShow("انجام نشد", False)
	Else
		'Add a new page to the container just behind the current page
		container.AddPageAt(CreatePanel(ret + 1, names.Get(ret)), names.Get(ret), pager.CurrentPage + 1)
		'Inform the AHViewPagerTabs object that the data has changed.
		tabs.NotifyDataChange
		'Slide to the new page
		pager.GotoPage(pager.CurrentPage + 1, True)
	End If
End Sub

Sub DeletePage_Click
	'Delete the current page
	container.DeletePage(pager.CurrentPage)
	'Inform the AHViewPagerTabs object that the data has changed.
	tabs.NotifyDataChange
End Sub

'This event gets called when the page has changed. Be aware that it is possible that scrolling is not
'finished at this moment
Sub Pager_PageChanged (Position As Int)
	Log ("Page Changed to " & Position)
	CurrentPage = Position
	SetButtonText
End Sub

'This event gets called when the ViewPager instantiates the page. In this sub you can update the content
'of the page or even load a layout.
'Have a look in the logs to see when Pager_PageCreated and Pager_PageDestroyed are called.


'This event gets called when the ViewPager destroys the page. Here you can free large bitmaps etc to save memory.
Sub Pager_PageDestroyed (Position As Int, Page As Object)
	Log("Page destroyed " & Position)
End Sub

Sub SetButtonText
	Button1.Text = "منو " 
End Sub

'When the button is pressed let the user select a new page
Sub Button1_Click
	Dim pl As List
	Dim ret As Int
	pl.Initialize
	
	'Add all page titles to a list
	For i = 0 To container.Count - 1
		pl.Add(container.GetTitle(i))	
	Next
	
	'Request new page from user
	ret = InputList(pl, "Choose page", pager.CurrentPage)
	
	If ret = DialogResponse.CANCEL Then
		ToastMessageShow("انجام نشد", False)
	Else
		'Scroll to the new page
		pager.GotoPage(ret, True)
	End If
End Sub

Sub SetTheme(Theme As Int)
	Select Theme
		Case 0
			tabs.Color = Colors.Black
			tabs.BackgroundColorPressed = Colors.Blue
			tabs.LineColorCenter = Colors.Green
			tabs.TextColor = Colors.LightGray
			tabs.TextColorCenter = Colors.Green
			line.Color = Colors.Green
		Case 1
			tabs.Color = Colors.White
			tabs.BackgroundColorPressed = Colors.Blue
			tabs.LineColorCenter = Colors.DarkGray
			tabs.TextColor = Colors.LightGray
			tabs.TextColorCenter = Colors.DarkGray
			line.Color = Colors.DarkGray
	End Select
End Sub

Sub spTheme_ItemClick (Position As Int, Value As Object)
	CurrentTheme = Position
	SetTheme(CurrentTheme)
End Sub

Sub Pager_PageCreated (Position As Int, Page As Object)
	Log ("Page created " & Position)
	
	Dim pan As Panel
	Dim pi As PanelInfo
	
	pan = Page
	pi = pan.Tag
	
	Select pi.PanelType
		Case TYPE_SETTINGS
			If Not(pi.LayoutLoaded) Then
				pan.LoadLayout("settings")
				pi.LayoutLoaded = True
				spTheme.Add("تیره")
				spTheme.Add("روشن")
				spTheme.SelectedIndex = CurrentTheme
			End If
	End Select		
End Sub


Sub lv1_ItemClick (Position As Int, Value As Object)
Position=Position+1
mp=Position
	StartActivity(player)
		ToastMessageShow("برای انتخاب زنگ روی تصویر کلیک کنید",False)
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
		If KeyCode = KeyCodes.KEYCODE_BACK Then
 a = Msgbox2("داری میری؟","خروج از برنامه","آره","فعلا نه","",LoadBitmap(File.DirAssets,"ex.png"))
	If (a = DialogResponse.POSITIVE) Then
	Activity.Finish
	 End If
	 Return True
	 

Else

Return False
End If 
End Sub

player

#Region  Activity Attributes 
	#FullScreen: True
	#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 Mediaplayer1 As MediaPlayer
Dim timer1 As Timer


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 Bitmap2,Bitmap3 As Bitmap

	Dim play As Button
	Dim SeekBar1 As SeekBar
	Dim Label2 As Label
	Dim Label3 As Label
	
	Dim r As RingtoneManager
	  Dim u As String
    Dim i As Int
	
	
	
	Dim Button1 As Button
	Dim Button2 As Button
	
	
    Dim titr As String
	Private Lab As Label
	Dim List1 As List
	
	Private Button3 As Button
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("play")
	
	Bitmap2.Initialize(File.DirAssets,"play.png")
	Bitmap3.Initialize(File.DirAssets,"pause.png")
	
	
	
	
	
	 List1 = File.ReadList(File.DirAssets, "list.txt")
	 titr=List1.Get(main1.mp)
     Lab.Text=titr
	  Lab.Gravity=Gravity.right
	Lab.Left=Lab.Left-70dip
	Lab.Top=5dip
	Lab.TextColor = Colors.White
	Lab.TextSize  =35
	Lab.Typeface=Typeface.LoadFromAssets("Titr.ttf")
		
		
	  
	
	

  
    If main1.mp=1 Then
  
  Mediaplayer1.Initialize()
	Mediaplayer1.Load(File.DirAssets,"1a.mp3")
	Mediaplayer1.play
	timer1.Initialize("timer1", 1000)
	timer1.Enabled=True
	
  End If
  
  
  
  
   If main1.mp=2 Then
  
  Mediaplayer1.Initialize()
	Mediaplayer1.Load(File.DirAssets,"2a.mp3")
	Mediaplayer1.play
	timer1.Initialize("timer1", 1000)
	timer1.Enabled=True
	
	End If
	
  
  If main1.mp=3 Then
  
  Mediaplayer1.Initialize()
	Mediaplayer1.Load(File.DirAssets,"3a.mp3")
	Mediaplayer1.play
	timer1.Initialize("timer1", 1000)
	timer1.Enabled=True
	
	End If
	
  
  
	
End Sub

Sub pl

 
    List1 = File.ReadList(File.DirAssets, "list.txt")
	 titr=List1.Get(main1.mp)
     Lab.Text=titr
	 
	 
	 
    If main1.mp=1 Then
  
  Mediaplayer1.Initialize()
	Mediaplayer1.Load(File.DirAssets,"1a.mp3")
	Mediaplayer1.play
  End If
  
  
  
  
   If main1.mp=2 Then
  
  Mediaplayer1.Initialize()
	Mediaplayer1.Load(File.DirAssets,"2a.mp3")
	Mediaplayer1.play
	End If
	
  
  If main1.mp=3 Then
  
  Mediaplayer1.Initialize()
	Mediaplayer1.Load(File.DirAssets,"3a.mp3")
	Mediaplayer1.play
	End If
	
	
		
	
End Sub




Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub timer1_Tick
    If Mediaplayer1.IsPlaying Then
       SeekBar1.Value = Mediaplayer1.Position / Mediaplayer1.Duration * 100
       '' lblPosition.Text = "Position: " & ConvertToTimeFormat(Mediaplayer1.Position) & _
         ''   " (" & ConvertToTimeFormat(Mediaplayer1.Duration) & ")"
		  Label2.Text= ConvertToTimeFormat(Mediaplayer1.Position)    'شده اجرا زمان
		   Label3.Text= ConvertToTimeFormat(Mediaplayer1.Duration)    'کل زمان'
    End If
	
End Sub

Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
    If UserChanged = False Then Return 'the value was changed programmatically
    Mediaplayer1.Position = Value / 100 * Mediaplayer1.Duration
    timer1_Tick 'immediately update the progress label
End Sub
Sub ConvertToTimeFormat(ms As Int) As String      'زمان تبدیل تابع'
    Dim seconds, minutes As Int
    seconds = Round(ms / 1000)
    minutes = Floor(seconds / 60)
    seconds = seconds Mod 60
    Return NumberFormat(minutes, 1, 0) & ":" & NumberFormat(seconds, 2, 0) 'ex: 3:05
End Sub
Sub back_Click
If main1.mp=1 Then
main1.mp=3

End If
	main1.mp=main1.mp-1
	Mediaplayer1.Pause
	pl
End Sub
Sub play_Click

	If Mediaplayer1.IsPlaying Then 
Mediaplayer1.Pause
play.SetBackgroundImage(Bitmap2)
Else
Mediaplayer1.play
play.SetBackgroundImage(Bitmap3)
End If



End Sub
Sub nex_Click
If main1.mp=3 Then
main1.mp=1
End If



main1.mp=main1.mp+1
Mediaplayer1.Pause

	pl
End Sub

Sub Button1_click


  i = Msgbox2("آیا می خواهید  به عنوان آهنگ گوشی خود انتخاب کنید؟","اخطار","آری","خیر","",LoadBitmap(File.DirAssets,"accep.png"))
	If i = DialogResponse.POSITIVE Then
	ToastMessageShow("آهنگ انتخاب شد",True)
	
	End If


     If main1.mp=1 Then
	
    u =r.AddToMediaStore(File.DirRootExternal,"1a.mp3","رینگتون1",True,True,True,True)
	r.SetDefault(r.TYPE_RINGTONE,u)
	File.Copy(File.DirAssets,"1a.mp3" , File.DirRootExternal ,"/1a.mp3")
	
	End If
	
	
	 If main1.mp=2 Then
	
	
    u =r.AddToMediaStore(File.DirRootExternal,"2a.mp3","رینگتون2",True,True,True,True)
	r.SetDefault(r.TYPE_RINGTONE,u)
	File.Copy(File.DirAssets,"2a.mp3" , File.DirRootExternal ,"/2a.mp3")
	
	
		End If
	
	 If main1.mp=3 Then
	
	
    u =r.AddToMediaStore(File.DirRootExternal,"3a.mp3","رینگتون3",True,True,True,True)
	r.SetDefault(r.TYPE_RINGTONE,u)
	File.Copy(File.DirAssets,"3a.mp3" , File.DirRootExternal ,"/3a.mp3")
	
		End If
   
		
End Sub



Sub Activity_KeyPress (KeyCode As Int) As Boolean 
		If KeyCode = KeyCodes.KEYCODE_BACK Then
		Mediaplayer1.Pause
		
		End If
		
		
End Sub

Sub Button2_Click

	StartActivity(main1)
	Activity.Finish
	Mediaplayer1.Pause
End Sub



Sub Button3_click


  i = Msgbox2("آیا می خواهید  به عنوان آهنگ پیام خود انتخاب کنید؟","اخطار","آری","خیر","",LoadBitmap(File.DirAssets,"accep.png"))
	If i = DialogResponse.POSITIVE Then
	ToastMessageShow("آهنگ انتخاب شد",True)
	
	End If


     If main1.mp=1 Then
	
    u =r.AddToMediaStore(File.DirRootExternal,"1a.mp3","رینگتون1",True,True,True,True)
	r.SetDefault(r.TYPE_NOTIFICATION,u)
	File.Copy(File.DirAssets,"1a.mp3" , File.DirRootExternal ,"/1a.mp3")
	
	End If
	
	
	 If main1.mp=2 Then
	
	
    u =r.AddToMediaStore(File.DirRootExternal,"2a.mp3","رینگتون2",True,True,True,True)
	r.SetDefault(r.TYPE_NOTIFICATION,u)
	File.Copy(File.DirAssets,"2a.mp3" , File.DirRootExternal ,"/2a.mp3")
	
	
		End If
	
	 If main1.mp=3 Then
	
	
    u =r.AddToMediaStore(File.DirRootExternal,"3a.mp3","رینگتون3",True,True,True,True)
	r.SetDefault(r.TYPE_NOTIFICATION,u)
	File.Copy(File.DirAssets,"3a.mp3" , File.DirRootExternal ,"/3a.mp3")
	
		End If
   
		
End Sub


اینم از همه کد

اگه متوجه نشدین اون فایل 7 مگ هست دانلود کنین

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

اگه فقط کد player رو میذاشتین کافی بودا. :S

من توی کد خیلی اشتباه دیدم ، اصلا استاندارد نیست ، مثلا بجای اینکه از else If استفاده بشه یه عالمه دستور if نوشتید.

بعدشم باید شرط گذاشته بشه اگه روی بله کلیک کرد صدای زنگ تنظیم بشه اما شما اصلا خارج از دستور مسیج باکس نوشتید...

اینجوری برنامه تون اصلا بهینه نیست.

پیشنهاد میکنم این سورس آهنگ زنگ رو ببینید.

http://answercenter.ir/topic/3881-%D8%B3%D9%88%D8%B1%D8%B3-%D9%82%D8%B1%D8%A7%D8%B1-%D8%AF%D8%A7%D8%AF%D9%86-%DB%8C%DA%A9-%D8%A2%D9%87%D9%86%DA%AF-%D8%A8%D8%B1%D8%A7%DB%8C-%D8%B5%D8%AF%D8%A7%DB%8C-%D8%B2%D9%86%DA%AF-%D8%A8%D8%AF%D9%88%D9%86-%D9%85%D8%B4%DA%A9%D9%84-%D8%AA%DA%A9%D8%B1/

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

بایگانی شده

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

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

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