Help needed with Android Studio Project. Getting a java error.

+1 Matthew Goodman · November 18, 2015
Hi, in my android studio project, I have been getting an error and I've been trying to resolve it for the last couple hours.
The error is: "Unhandled exception:java.text.ParseException"
This error pops up on the following three lines in my code posted below:
Date date1a = format1.parse(starttime1);
Date date1b = format1.parse(endtime1);
Date datenow1 = format1.parse(currenttime1);
What I want my app to do:
When I click a button, I want the code to check what time is it and if it is between two times listed. If so, it will then display my next school course that day.
I have a working eclipse version in which it prints what I have next into console. But now I want to make it into an app. The link containing the java file explains pretty well what I want my app to do. It is accessible here:
Help would much be appreciated. Feel free to ask me questions.
package com.ib_personalproject.matthewgoodman.classschedule2015;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.InputMismatchException;
import java.text.ParseException;

public class MainActivity extends ActionBarActivity {

    protected void onCreate(Bundle savedInstanceState) {

        int cycleDay = 0;

        Button day1button = (Button) findViewById(;

                new Button.OnClickListener() {
                    public void onClick(View v)  {
                        int cycleDay = 1;

                        if (cycleDay == 1) {   //DAY1

                            SimpleDateFormat format1 = new SimpleDateFormat("HH:mm:ss");

                            String starttime1 = "00:00:00";
                            String endtime1 = "08:50:00";

                            Date date1a = format1.parse(starttime1);
                            Date date1b = format1.parse(endtime1);

                            Calendar cal1 = Calendar.getInstance();

                            String currenttime1 = format1.format(cal1.getTime());
                            Date datenow1 = format1.parse(currenttime1);

                            if (date1a.getTime() < datenow1.getTime() && date1b.getTime() > datenow1.getTime()){
                                TextView messagetext = (TextView) findViewById(;
                                messagetext.setText("First class is ENGLISH then MUSIC!");

                        else {
                            TextView messagetext = (TextView) findViewById(;
                            messagetext.setText("No Classes");

        public boolean onCreateOptionsMenu (Menu menu){
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(, menu);
            return true;

        public boolean onOptionsItemSelected (MenuItem item){
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();

            //noinspection SimplifiableIfStatement
            if (id == {
                return true;

            return super.onOptionsItemSelected(item);

Post a Reply


Oldest  Newest  Rating
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator