Friday, May 13, 2016

Binding, Views, Public, Static, and Frustration

I'm in the process of writing my first app. A way to arrange products so they can be showed to a potential customer. I'm doing it for a friend with a car detailing business so it is specialized to that. After I finish it for him I plan on generalizing it so it can be used for other businesses.

The second app walk-through in the Treehouse Android course is a weather app. In it you must send information from one page to another and display it in a list. This is the format I used to write the code for the car detailing product app. It should also be noted I'm using Android Studio and have the Butterknife API.

The biggest obstacle I had, spent 5 hours on, and stayed up util 1 am* trying to solve was binding variables to the xml items in the list view. I kept getting a 'Null Pointer Exception - Attempt to get length of a null array'(loosely quoting) and it said to possibly add @Nullable. It was a rough night as searched and searched but couldn't find anything that would make it work. I finally ended up writing the adapter code again and somehow it worked this time. I don't know how I fixed it as I merely duplicated other code and changed variable names, but in the end it finally worked. I was so happy to go to bed.

The following day a challenge I had was creating an array of different services. I wrote a class that would populate arrays of products for the different categories of services. However I couldn't access them from the main activity and I didn't know why. So I ended up just writing methods in the main activity. It worked but it wasn't as organized as it could be. Looking at other code I found if I wrote those functions to populate product information public and static instead of private, they could be accessed by other activities and classes. It was really a simple fix and I should have seen it. However the triumphant feeling of overcoming the challenge overpowered any feelings of inadequacy.

As of now the app functions correctly and only needs to be cosmetically enhanced. I would also like to add the following features:
  • Showing before and after photos of products offered
  • Adding and deleting products
  • A way to edit the product names and descriptions
Also instead of getting the product information from a class, it would probably be better to have a database in the app. However that is beyond my knowledge. I know some SQL and how to integrate it with websites and PHP but I don't know how to have it in an Android app. I do believe there is a course or workshop on Treehouse that discusses that.

* I realize if you are a programmer 1 am is likely considered barely a late night trying to fix a bug.

No comments:

Post a Comment