1. Download our Official Android App: Forums for Android!

Android Studio and debug output

Discussion in 'Android Development' started by Gregary Boyles, Oct 1, 2017.

  1. Gregary Boyles

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    30
    Joined:
    Oct 1, 2017

    Oct 1, 2017
    30
    0
    15
    I have tried using log.d("...", "....") but my debug output does not appear in android monitor logcat.

    So what else do I need to do to view my debug output?
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,460
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,460
    10,745
    1,988
    Male
    Software developer
    South West of England
    It's possible that the code which includes the log statements wasn't executed.
    Can you include your code please?
     
  3. Gregary Boyles

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    30
    Joined:
    Oct 1, 2017

    Oct 1, 2017
    30
    0
    15
    Have I set this custom application class up incorrectly?


    package com.example.greg.irrigationcontroller;

    import android.app.Application;
    import android.content.res.Configuration;
    import java.util.Calendar;
    import android.util.Log;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io_ObjectInputStream;
    import java.io_ObjectOutputStream;
    import java.util.ArrayList;

    /**
    * Created by Greg on 24/09/2017.
    */

    public class CIrrigationApplication extends Application
    {
    /** Class representing an individual watering time and duration. */
    public class CWateringTime
    {
    /** Constructor */
    public CWateringTime()
    {

    }
    /** Constructor */
    public CWateringTime(final int nHour, final int nMinutes, final int nOnTime)
    {
    m_nHour = nHour;
    m_nMinutes = nMinutes;
    m_nOnTime = nOnTime;
    }
    /** Dump irrigation settings to event log window */
    protected void Dump()
    {
    Log.d("", String.valueOf(m_nHour) + ":" + String.valueOf(m_nMinutes) + "(" + String.valueOf(m_nOnTime) + ")");

    }
    /** Implentation */
    public int m_nHour, m_nMinutes, m_nOnTime;
    }

    /** Class representing an individual watering day list of watering times. */
    public class CWateringDay
    {
    /** Constructor */
    public CWateringDay()
    {
    m_arrayWateringTimes = new ArrayList<CWateringTime>();
    }
    public CWateringDay(final int nDOM, final int nMonth)
    {
    m_nDOM = nDOM;
    m_nMonth = nMonth;
    m_arrayWateringTimes = new ArrayList<CWateringTime>();
    }
    /** Add a new watering time to the watering time this watering day */
    public void AddWateringTime(final int nHour, final int nMinute, final int nOnTime)
    {
    m_arrayWateringTimes.add(new CWateringTime(nHour, nMinute, nOnTime));
    }

    /** Dump irrigation settings to event log window */
    protected void Dump()
    {
    Log.d("", String.valueOf(m_nDOM) + "/" + String.valueOf(m_nMonth) + " => ");

    CWateringTime WateringTime = new CWateringTime();
    for (int nI = 0; nI < m_arrayWateringTimes.size(); nI++)
    {
    WateringTime = m_arrayWateringTimes.get(nI);
    WateringTime.Dump();
    }
    }
    /** Implentation */
    public int m_nDOM, m_nMonth;
    public ArrayList<CWateringTime> m_arrayWateringTimes;
    }

    /** Class representing an individual station with a list of watering days. */
    public class CStation
    {
    /** Constructor */
    public CStation(final int nStation)
    {
    m_nStation = nStation;
    m_bActive = false;
    m_arrayWateringDays = new ArrayList<CWateringDay>();
    }
    /** Dump irrigation settings to event log window */
    protected void Dump()
    {
    Log.d("m_bActive = ", String.valueOf(m_bActive));
    Log.d("m_nStation = ", String.valueOf(m_nStation));

    CWateringDay WateringDay = new CWateringDay();
    for (int nI = 0; nI < m_arrayWateringDays.size(); nI++)
    {
    WateringDay = m_arrayWateringDays.get(nI);
    WateringDay.Dump();
    }
    }

    /** Implentation */
    public int m_nStation;
    public boolean m_bActive;
    public ArrayList<CWateringDay> m_arrayWateringDays;
    }

    /** Constructor */
    public CIrrigationApplication()
    {
    m_dateFrom = Calendar.getInstance();
    m_dateTo = Calendar.getInstance();
    m_timeFrom =Calendar.getInstance();
    m_timeTo = Calendar.getInstance();
    }

    // Called by the system when the device configuration changes while your component is running.
    // Overriding this method is totally optional!
    @override
    public void onConfigurationChanged(Configuration newConfig)
    {
    super.onConfigurationChanged(newConfig);
    }

    // This is called when the overall system is running low on memory,
    // and would like actively running processes to tighten their belts.
    // Overriding this method is totally optional!
    @override
    public void onLowMemory()
    {
    super.onLowMemory();
    }

    /** Overrides */
    @override
    public void onCreate()
    {
    super.onCreate();
    for (int nI = 0; nI < m_nMaxStations; nI++)
    m_arrayStations[nI] = new CStation(nI + 1);
    GetSettings();
    Dump();
    }

    /** Save irrigation settings from the data file */
    protected void PutSettings()
    {
    try
    {
    FileOutputStream file = new FileOutputStream(m_strDataFileName);
    ObjectOutputStream stream = new ObjectOutputStream(file);
    stream.writeObject(m_arrayStations[m_nStation].m_arrayWateringDays);
    stream.close();
    file.close();
    }
    catch(IOException ioe)
    {
    System.out.println(ioe.getMessage());
    return;
    }
    }

    /** Read irrigation settings from the data file */
    protected void GetSettings()
    {
    try
    {
    FileInputStream file = new FileInputStream(m_strDataFileName);
    ObjectInputStream stream = new ObjectInputStream(file);
    m_arrayStations[m_nStation].m_arrayWateringDays = (ArrayList<CWateringDay>) stream.readObject();
    stream.close();
    file.close();
    }
    catch (IOException ioe)
    {
    System.out.println(ioe.getMessage());
    return;
    }
    catch (ClassNotFoundException ioe)
    {
    System.out.println(ioe.getMessage());
    return;
    }
    }

    /** Dump irrigation settings to event log window */
    protected void Dump()
    {
    for (int nI = 0; nI < m_nMaxStations; nI++)
    {
    m_arrayStations[nI].Dump();
    }
    }

    /** Add a new watering day to the array and return its index */
    public int AddWateringDay(final int nDOM, final int nMonth)
    {
    if ((m_nStation >= 0) && (m_nStation < m_nMaxStations))
    {
    m_arrayStations[m_nStation].m_arrayWateringDays.add(new CWateringDay(nDOM, nMonth));
    return m_arrayStations[m_nStation].m_arrayWateringDays.size() - 1;
    }
    return -1;
    }
    /** Add a new watering time to the watering day specified by nI */
    public void AddWateringTime(final int nI, final int nHour, final int nMinute, final int nOnTime)
    {
    if ((m_nStation >= 0) && (m_nStation < m_nMaxStations))
    {
    if ((nI >= 0) && (nI < m_arrayStations[m_nStation].m_arrayWateringDays.size()))
    {
    CWateringDay WateringDay = m_arrayStations[m_nStation].m_arrayWateringDays.get(nI);
    WateringDay.AddWateringTime(nHour, nMinute, nOnTime);
    m_arrayStations[m_nStation].m_arrayWateringDays.set(nI, WateringDay);
    }
    }
    }
    /** Add a new watering time to the watering day specified by nI */
    public void AddWateringTime(final int nI, CWateringTime WateringTime)
    {
    AddWateringTime(nI, WateringTime.m_nHour, WateringTime.m_nMinutes, WateringTime.m_nOnTime);
    }

    public void ClearCurrentStationWateringDays()
    {
    m_arrayStations[m_nStation].m_arrayWateringDays.clear();
    }
    public boolean SettingsEmpty()
    {
    return (m_nStation >= 0) && (m_nStation < m_nMaxStations) && (m_arrayStations[m_nStation].m_arrayWateringDays.size() > 0);
    }

    /** Global data. */
    public Calendar m_dateFrom, m_dateTo, m_timeFrom, m_timeTo;
    public int m_nStation, m_nFreq1, m_nFreq2, m_nHourFreq, m_nOnTime;
    public final int m_nMaxStations = 24;
    protected CStation[] m_arrayStations = new CStation[m_nMaxStations];
    protected String m_strDataFileName = "irrigation.dat";
    }
     
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,460
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,460
    10,745
    1,988
    Male
    Software developer
    South West of England
    Your code is difficult to read. Can you please enclose the code in [code][/code] tags, and separate the various classes into different sections.
     
  5. Gregary Boyles

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    30
    Joined:
    Oct 1, 2017

    Oct 1, 2017
    30
    0
    15
    Where the buggery is the little button above the edit window that inserts the code tags??? No such button as far as I can see.
    Have I set this custom application class up incorrectly?

    Code (Text):
    1.  
    2. package com.example.greg.irrigationcontroller;
    3.  
    4. import android.app.Application;
    5. import android.content.res.Configuration;
    6. import java.util.Calendar;
    7. import android.util.Log;
    8. import java.io.FileInputStream;
    9. import java.io.FileOutputStream;
    10. import java.io.IOException;
    11. import java.io_ObjectInputStream;
    12. import java.io_ObjectOutputStream;
    13. import java.util.ArrayList;
    14.  
    15. /**
    16. * Created by Greg on 24/09/2017.
    17. */
    18.  
    19. public class CIrrigationApplication extends Application
    20. {
    21. /** Class representing an individual watering time and duration. */
    22. public class CWateringTime
    23. {
    24. /** Constructor */
    25. public CWateringTime()
    26. {
    27.  
    28. }
    29. /** Constructor */
    30. public CWateringTime(final int nHour, final int nMinutes, final int nOnTime)
    31. {
    32. m_nHour = nHour;
    33. m_nMinutes = nMinutes;
    34. m_nOnTime = nOnTime;
    35. }
    36. /** Dump irrigation settings to event log window */
    37. protected void Dump()
    38. {
    39. Log.d("", String.valueOf(m_nHour) + ":" + String.valueOf(m_nMinutes) + "(" + String.valueOf(m_nOnTime) + ")");
    40.  
    41. }
    42. /** Implentation */
    43. public int m_nHour, m_nMinutes, m_nOnTime;
    44. }
    45.  
    46. /** Class representing an individual watering day list of watering times. */
    47. public class CWateringDay
    48. {
    49. /** Constructor */
    50. public CWateringDay()
    51. {
    52. m_arrayWateringTimes = new ArrayList<CWateringTime>();
    53. }
    54. public CWateringDay(final int nDOM, final int nMonth)
    55. {
    56. m_nDOM = nDOM;
    57. m_nMonth = nMonth;
    58. m_arrayWateringTimes = new ArrayList<CWateringTime>();
    59. }
    60. /** Add a new watering time to the watering time this watering day */
    61. public void AddWateringTime(final int nHour, final int nMinute, final int nOnTime)
    62. {
    63. m_arrayWateringTimes.add(new CWateringTime(nHour, nMinute, nOnTime));
    64. }
    65.  
    66. /** Dump irrigation settings to event log window */
    67. protected void Dump()
    68. {
    69. Log.d("", String.valueOf(m_nDOM) + "/" + String.valueOf(m_nMonth) + " => ");
    70.  
    71. CWateringTime WateringTime = new CWateringTime();
    72. for (int nI = 0; nI < m_arrayWateringTimes.size(); nI++)
    73. {
    74. WateringTime = m_arrayWateringTimes.get(nI);
    75. WateringTime.Dump();
    76. }
    77. }
    78. /** Implentation */
    79. public int m_nDOM, m_nMonth;
    80. public ArrayList<CWateringTime> m_arrayWateringTimes;
    81. }
    82.  
    83. /** Class representing an individual station with a list of watering days. */
    84. public class CStation
    85. {
    86. /** Constructor */
    87. public CStation(final int nStation)
    88. {
    89. m_nStation = nStation;
    90. m_bActive = false;
    91. m_arrayWateringDays = new ArrayList<CWateringDay>();
    92. }
    93. /** Dump irrigation settings to event log window */
    94. protected void Dump()
    95. {
    96. Log.d("m_bActive = ", String.valueOf(m_bActive));
    97. Log.d("m_nStation = ", String.valueOf(m_nStation));
    98.  
    99. CWateringDay WateringDay = new CWateringDay();
    100. for (int nI = 0; nI < m_arrayWateringDays.size(); nI++)
    101. {
    102. WateringDay = m_arrayWateringDays.get(nI);
    103. WateringDay.Dump();
    104. }
    105. }
    106.  
    107. /** Implentation */
    108. public int m_nStation;
    109. public boolean m_bActive;
    110. public ArrayList<CWateringDay> m_arrayWateringDays;
    111. }
    112.  
    113. /** Constructor */
    114. public CIrrigationApplication()
    115. {
    116. m_dateFrom = Calendar.getInstance();
    117. m_dateTo = Calendar.getInstance();
    118. m_timeFrom =Calendar.getInstance();
    119. m_timeTo = Calendar.getInstance();
    120. }
    121.  
    122. // Called by the system when the device configuration changes while your component is running.
    123. // Overriding this method is totally optional!
    124. @override
    125. public void onConfigurationChanged(Configuration newConfig)
    126. {
    127. super.onConfigurationChanged(newConfig);
    128. }
    129.  
    130. // This is called when the overall system is running low on memory,
    131. // and would like actively running processes to tighten their belts.
    132. // Overriding this method is totally optional!
    133. @override
    134. public void onLowMemory()
    135. {
    136. super.onLowMemory();
    137. }
    138.  
    139. /** Overrides */
    140. @override
    141. public void onCreate()
    142. {
    143. super.onCreate();
    144. for (int nI = 0; nI < m_nMaxStations; nI++)
    145. m_arrayStations[nI] = new CStation(nI + 1);
    146. GetSettings();
    147. Dump();
    148. }
    149.  
    150. /** Save irrigation settings from the data file */
    151. protected void PutSettings()
    152. {
    153. try
    154. {
    155. FileOutputStream file = new FileOutputStream(m_strDataFileName);
    156. ObjectOutputStream stream = new ObjectOutputStream(file);
    157. stream.writeObject(m_arrayStations[m_nStation].m_arrayWateringDays);
    158. stream.close();
    159. file.close();
    160. }
    161. catch(IOException ioe)
    162. {
    163. System.out.println(ioe.getMessage());
    164. return;
    165. }
    166. }
    167.  
    168. /** Read irrigation settings from the data file */
    169. protected void GetSettings()
    170. {
    171. try
    172. {
    173. FileInputStream file = new FileInputStream(m_strDataFileName);
    174. ObjectInputStream stream = new ObjectInputStream(file);
    175. m_arrayStations[m_nStation].m_arrayWateringDays = (ArrayList<CWateringDay>) stream.readObject();
    176. stream.close();
    177. file.close();
    178. }
    179. catch (IOException ioe)
    180. {
    181. System.out.println(ioe.getMessage());
    182. return;
    183. }
    184. catch (ClassNotFoundException ioe)
    185. {
    186. System.out.println(ioe.getMessage());
    187. return;
    188. }
    189. }
    190.  
    191. /** Dump irrigation settings to event log window */
    192. protected void Dump()
    193. {
    194. for (int nI = 0; nI < m_nMaxStations; nI++)
    195. {
    196. m_arrayStations[nI].Dump();
    197. }
    198. }
    199.  
    200. /** Add a new watering day to the array and return its index */
    201. public int AddWateringDay(final int nDOM, final int nMonth)
    202. {
    203. if ((m_nStation >= 0) && (m_nStation < m_nMaxStations))
    204. {
    205. m_arrayStations[m_nStation].m_arrayWateringDays.add(new CWateringDay(nDOM, nMonth));
    206. return m_arrayStations[m_nStation].m_arrayWateringDays.size() - 1;
    207. }
    208. return -1;
    209. }
    210. /** Add a new watering time to the watering day specified by nI */
    211. public void AddWateringTime(final int nI, final int nHour, final int nMinute, final int nOnTime)
    212. {
    213. if ((m_nStation >= 0) && (m_nStation < m_nMaxStations))
    214. {
    215. if ((nI >= 0) && (nI < m_arrayStations[m_nStation].m_arrayWateringDays.size()))
    216. {
    217. CWateringDay WateringDay = m_arrayStations[m_nStation].m_arrayWateringDays.get(nI);
    218. WateringDay.AddWateringTime(nHour, nMinute, nOnTime);
    219. m_arrayStations[m_nStation].m_arrayWateringDays.set(nI, WateringDay);
    220. }
    221. }
    222. }
    223. /** Add a new watering time to the watering day specified by nI */
    224. public void AddWateringTime(final int nI, CWateringTime WateringTime)
    225. {
    226. AddWateringTime(nI, WateringTime.m_nHour, WateringTime.m_nMinutes, WateringTime.m_nOnTime);
    227. }
    228.  
    229. public void ClearCurrentStationWateringDays()
    230. {
    231. m_arrayStations[m_nStation].m_arrayWateringDays.clear();
    232. }
    233. public boolean SettingsEmpty()
    234. {
    235. return (m_nStation >= 0) && (m_nStation < m_nMaxStations) && (m_arrayStations[m_nStation].m_arrayWateringDays.size() > 0);
    236. }
    237.  
    238. /** Global data. */
    239. public Calendar m_dateFrom, m_dateTo, m_timeFrom, m_timeTo;
    240. public int m_nStation, m_nFreq1, m_nFreq2, m_nHourFreq, m_nOnTime;
    241. public final int m_nMaxStations = 24;
    242. protected CStation[] m_arrayStations = new CStation[m_nMaxStations];
    243. protected String m_strDataFileName = "irrigation.dat";
    244. }
    245.  
     

Share This Page

Loading...