Help a novice to learn!

ThePuiu

Active Member
Licensed User
Longtime User
Hi, i tryed to draw a graph with a different sets of values. They are selected from a spinner control. For the first and second selection (no matter what value is selected) everything works well, but when i try to chose another value, my app crashed. The code is:
B4X:
Sub CreateGraph(Tip As Int)
   Dim p As Panel
   p.Initialize("")
   pnl2Lines.Initialize("pnl2Lines")
   p.AddView(pnl2Lines, 0, 0, 600%x, 100%y - 200dip)

   HView1.Panel.Initialize("controls")
   HView1.Panel.AddView(p,0,0,600%x,100%y - 200dip)
   Dim LD As LineData
   LD.Initialize
   LD.Target = pnl2Lines   
   
   Charts.AddLineColor(LD, Colors.Red) 'consum
   Charts.AddLineColor(LD, Colors.Green) 'productie
   Charts.AddLineColor(LD, Colors.Magenta) 'productie
   
   For i = 0 To NrValori Step 1
   If Tip = 0 Then
      Charts.AddLineMultiplePoints(LD, Valori(i).DATA, Array As Float(Valori(i).CONSUM/1000, Valori(i).PRODUCTIE/1000, Valori(i).CARBUNI/1000), i Mod 30 = 0)
   Else If Tip = 1 Then
      Charts.AddLineMultiplePoints(LD, Valori(i).DATA, Array As Float(Valori(i).CONSUM/1000, Valori(i).PRODUCTIE/1000, Valori(i).GAZE/1000), i Mod 30 = 0)
   Else If Tip = 2 Then
      Charts.AddLineMultiplePoints(LD, Valori(i).DATA, Array As Float(Valori(i).CONSUM/1000, Valori(i).PRODUCTIE/1000, Valori(i).APE/1000), i Mod 30 = 0)
   Else If Tip = 3 Then
      Charts.AddLineMultiplePoints(LD, Valori(i).DATA, Array As Float(Valori(i).CONSUM/1000, Valori(i).PRODUCTIE/1000, Valori(i).NUCLEAR/1000), i Mod 30 = 0)
   Else If Tip = 4 Then
      Charts.AddLineMultiplePoints(LD, Valori(i).DATA, Array As Float(Valori(i).CONSUM/1000, Valori(i).PRODUCTIE/1000, Valori(i).EOLIAN/1000), i Mod 30 = 0)
   End If
   Next
   Dim G As Graph
   G.Initialize
   G.Title = "Grafic Productie / Consum"
   G.YAxis = "GW"
   G.YStart = -1
   G.YEnd = 10
   G.YInterval = 1
   G.AxisColor = Colors.Black
   Charts.DrawLineChart(G, LD, Colors.White)
End Sub

Sub Combo_ItemClick (Position As Int, Value As Object)
   CreateGraph(Position)
End Sub

What am I doing wrong? Ty!
 

ThePuiu

Active Member
Licensed User
Longtime User
in the Logs does not apear anything, (last line is: ** Activity (main) Resume **) but my app get the message:
The application Energy (proces energy.soft) has stopped unexpectedly. Please try again. In debuger it crahs at the second selection.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Look at the unfiltered log, turn off the filter check box.
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
why after passing my app into the background when I try to reactivate not there anything on display ... even the activity menu is not accessible?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You must remove the FirstTime test because the layout is not loaded nor is it initialized when the run again.
I added the saving and reading of the data type in a setup file, so the user will get the last displayed diagram.

Best regards.
 

Attachments

  • Energy (4).zip
    10.5 KB · Views: 278
Upvote 0
Top