Я приписал всем полям значения по умолчанию, однако при изменении значений любого поля часа приложение закрывается, и я получаю следующую ошибку:
Код: Выделить всё
I/mple.dive_calc2(11766): Compiler allocated 4206KB to compile void android.widget.TextView.(android.content.Context, android.util.AttributeSet, int, int)
D/CompatChangeReporter(11766): Compat change id reported: 170233598; UID 10198; state: ENABLED
D/AndroidRuntime(11766): Shutting down VM
E/AndroidRuntime(11766): FATAL EXCEPTION: main
E/AndroidRuntime(11766): Process: com.example.dive_calc2, PID: 11766
E/AndroidRuntime(11766): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.widget.EditText.hasFocus()' on a null object reference
Это единственная функция, которая читает эти поля. Я также пытался комментировать ее, но она все равно закрывает мое приложение:
Код: Выделить всё
// Function to calculate the time difference in hours and minutes between two fields
async function calculateTimeDifference(startInputId, endInputId) {
const startTime = await document.getElementById(startInputId).value;
const endTime = await document.getElementById(endInputId).value;
// Check if the values are available
if (startTime && endTime) {
const startDate = new Date(`1970-01-01T${startTime}:00`);
const endDate = new Date(`1970-01-01T${endTime}:00`);
// Calculate the total difference in minutes
const totalMinutes = Math.abs((endDate - startDate) / 60000);
// Convert total minutes into hours and minutes
const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;
// Display the result in the console (or it can be used to generate a logbook)
console.log(`Time difference between ${startInputId} and ${endInputId}: ${hours} hours and ${minutes} minutes`);
// Return the formatted time (can be used in a PDF or logbook)
return { hours, minutes };
} else {
console.log(`One or both fields (${startInputId}, ${endInputId}) are empty.`);
return null;
}
}Когда HTML-код загружается внутри приложения, он получает 12 часов (AM/PM ) по умолчанию, хотя для эмулятора Android установлен 24-часовой режим.
В настоящее время использую macOS.
Некоторые вещи, которые я пробовал:
- Удаление функции, считывающей поля чч:мм.
- Размещение страницы в сети >
- Запуск функции только с помощью onPageFinished:
Подробнее здесь: https://stackoverflow.com/questions/790 ... pplication
Мобильная версия