KotlinCS 124 LogoJava
PrevIndexNext
Kotlin
Java
  • Implementing a Map : 04/26/2024

  • map-reduce-filter : 04/25/2024

  • Generics : 04/24/2024

  • Hashing : 04/23/2024

  • Binary Search : 04/22/2024

  • MP3: Course Ratings : 04/19/2024

  • Quicksort : 04/18/2024

  • Merge Sort : 04/17/2024

  • Sorting Algorithms : 04/16/2024

  • MP Debugging Part 1 : 04/15/2024

  • MP2: Course Activity : 04/12/2024

  • Practice with Recursion : 04/11/2024

  • MP Debugging Part 0 : 04/10/2024

  • MP2: API Client : 04/09/2024

  • MP2: API Server : 04/08/2024

  • Trees and Recursion : 04/05/2024

  • Trees : 04/04/2024

  • Recursion : 04/03/2024

  • MP1: Filtering and Search : 04/02/2024

  • MP1: Loading and Sorting : 04/01/2024

  • Lists Review and Performance : 03/29/2024

  • Linked Lists : 03/28/2024

  • Algorithms and Lists : 03/27/2024

  • Continuing MP0 : 03/26/2024

  • Getting Started with MP0 : 03/25/2024

  • Lambda Expressions : 03/22/2024

  • Anonymous Classes : 03/21/2024

  • Practice with Interfaces : 03/20/2024

  • Implementing Interfaces : 03/19/2024

  • Using Interfaces : 03/18/2024

  • Working with Exceptions : 03/08/2024

  • Throwing Exceptions : 03/07/2024

  • Catching Exceptions : 03/06/2024

  • References and Polymorphism : 03/05/2024

  • References : 03/04/2024

  • Data Modeling 2 : 03/01/2024

  • Equality and Object Copying : 02/29/2024

  • Polymorphism : 02/28/2024

  • Inheritance : 02/27/2024

  • Data Modeling 1 : 02/26/2024

  • Companion Objects : 02/23/2024

  • Encapsulation : 02/22/2024

  • Constructors : 02/21/2024

  • Objects, Continued : 02/20/2024

  • Introduction to Objects : 02/19/2024

  • Compilation and Immutability : 02/16/2024

  • Practice with Collections : 02/15/2024

  • Maps and Sets : 02/14/2024

  • Lists and Type Parameters : 02/13/2024

  • Imports and Libraries : 02/12/2024

  • Multidimensional Arrays : 02/09/2024

  • Practice with Strings : 02/08/2024

  • null : 02/07/2024

  • Algorithms and Strings : 02/06/2024

  • Strings : 02/05/2024

  • Functions and Algorithms : 02/02/2024

  • Practice with Functions : 02/01/2024

  • More About Functions : 01/31/2024

  • Errors and Debugging : 01/30/2024

  • Functions : 01/29/2024

  • Practice with Loops and Algorithms : 01/26/2024

  • Algorithms : 01/25/2024

  • Loops : 01/24/2024

  • Arrays : 01/23/2024

  • Compound Conditionals : 01/22/2024

  • Conditional Expressions and Statements : 01/19/2024

  • Operations on Variables : 01/18/2024

  • Variables and Types : 01/17/2024

  • Welcome to CS 124 : 01/16/2024

MP Debugging Part 1

Welcome back! This short lesson is our second on debugging strategies that will both help you with your project, and in your future as a software creator.

This lesson completes the checklist that we’ll expect you to have followed before you receive help on the tutoring site. But we also expect that, by following these steps, you’ll find your mistakes faster, with less frustration, and needing less help from us. So let’s get to it!

Steps 0, 1, and 2
Steps 0, 1, and 2

If you haven’t already, check out the previous lesson on debugging for the first three steps in our checklist. To review, they are:

  1. Tidy up your code, so that you and we can read it
  2. Identify the problem by examining the test cases and being able to explain how your code is behaving differently than expected
  3. Add log messages to help test hypotheses and understand how your code is actually behaving

Step 3: Reading Exception Stack Traces
Step 3: Reading Exception Stack Traces

When you encounter an error in your program, frequently a piece of debugging output called a stack trace is generated. Here’s an example drawn from the video walkthrough below:

java.lang.ExceptionInInitializerError
at edu.illinois.cs.cs124.ay2023.mp.network.ServerKt.startServer(Server.kt:149)
at edu.illinois.cs.cs124.ay2023.mp.application.CourseableApplication.onCreate(CourseableApplication.kt:18)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1266)
at org.robolectric.android.internal.RoboMonitoringInstrumentation.callApplicationOnCreate(RoboMonitoringInstrumentation.java:148)
at org.robolectric.android.internal.AndroidTestEnvironment.lambda$installAndCreateApplication$2(AndroidTestEnvironment.java:381)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:86)
at org.robolectric.android.internal.AndroidTestEnvironment.installAndCreateApplication(AndroidTestEnvironment.java:379)
at org.robolectric.android.internal.AndroidTestEnvironment.lambda$createApplicationSupplier$0(AndroidTestEnvironment.java:250)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
at org.robolectric.android.internal.AndroidTestEnvironment.lambda$createApplicationSupplier$1(AndroidTestEnvironment.java:247)
at com.google.common.base.Suppliers$NonSerializableMemoizingSupplier.get(Suppliers.java:183)
at org.robolectric.RuntimeEnvironment.lambda$getApplication$0(RuntimeEnvironment.java:80)
at org.robolectric.shadows.ShadowInstrumentation.runOnMainSyncNoIdle(ShadowInstrumentation.java:1201)
at org.robolectric.RuntimeEnvironment.getApplication(RuntimeEnvironment.java:80)
at org.robolectric.android.internal.AndroidTestEnvironment.setUpApplicationState(AndroidTestEnvironment.java:215)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:340)
at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$2(SandboxTestRunner.java:281)
at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:101)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException

Initially, this looks like a pretty intimidating mound of text! But, buried within are some incredibly useful nuggets of information. And by familiarizing yourself with stack traces and their contents, you can frequently at least figure out what is going wrong, and sometimes the solution as well. Let’s explore how to read exception stack traces, and use them to understand what is going wrong with our code.

Step 4: Searching for Help
Step 4: Searching for Help

Next comes the part where the old geezer faculty member is going to tell you how to use the internets. Search? I can tell what you’re thinking. Really? You’re going to show me how to search the internet? I know how to do that!

I don’t doubt it. But, nonetheless, I have a few tips that you might find useful.

Bonus Step: Using Git to Identify and Undo Changes
Bonus Step: Using Git to Identify and Undo Changes

We consciously avoided covering too many details about Git in this course. You’ll learn more about it in later courses, and on some level Git can’t really be properly understood outside of a collaborative multi-person project.

But, it’s worth knowing how to do a few simple things. Let’s discuss two Git fundamentals—determining what you’ve changed, and undoing those changes when you’ve made a mistake.

Summary
Summary

That’s all for this lesson! To recap, going forward, here are the steps that we’ll expect you have to completed before you ask for help using the help site or forum:

  1. Tidy up your code, so that you and we can read it
  2. Identify the problem by examining the test cases and being able to explain how your code is behaving differently than expected
  3. Add log messages to help test hypotheses and understand how your code is actually behaving
  4. Understand any relevant exception stack traces to gain a clearer picture of what is going wrong
  5. Have searched the forum and Google as appropriate to find out more information about what went wrong

More Practice

Need more practice? Head over to the practice page.