• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android Studio and debug output

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?
 
It's possible that the code which includes the log statements wasn't executed.
Can you include your code please?
 
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";
}
 
Your code is difficult to read. Can you please enclose the code in [code][/code] tags, and separate the various classes into different sections.
 
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:
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";
}
 
Back
Top Bottom