Android Studio Error Log

Here are all of the errors I’ve encountered in Android Studio, what they mean, and how to solve them.

(This will be updated regularly)

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity; context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

I got this error by creating an adapter from MainActivity like this.

adapter = new MainCardAdapter(getApplicationContext());

Then in the adapter, I attempted to create a new Intent and start that Intent.

public MainCardAdapter(Context context)
    this.context = context;

public void onClick(View v)
    Intent i = new Intent(context, ResumeSectionsActivity.class);

The error came up because I was starting the new task from outside of the activity. I thought this was odd because I passed “GetApplicationContext()” for an argument. I thought that would include the MainActivity but apparently it does not. I fixed this error by sending “this” as an argument for context like so.

adapter = new MainCardAdapter(this);

A Good Programmer is like a Good Chef

Learning programming is like learning how to cook.  At first, it's daunting, and best left to those that know what they're doing.  But the day will come when you need to learn how to do it yourself.  That is, if you don't want to keep paying other people to do it for you.  So you start with something small and easy that's been done before and has a lot of very detailed instructions.  When it's done you feel amazing!  You have something tangible, right in front of you, that you made and can be proud of.  An unnoticeable victory for the rest of the world but a milestone for you!

Then you get the itch to do it a little better next time so you try cooking something a little more challenging.  It has a few more steps to it, some of which you have to get a second opinion on to make sure you're doing them correctly.  You make a few mistakes and learn a couple things along the way but you make progress.  You keep trying again and again, each time adding a step or two you've never done before.  Sometimes you go back to the easy recipes because you need that confidence boost, that reminder that you can do it.  And then you move on.  Eventually you're using ingredients you didn't even know existed and cooking dishes with names you could barely pronounce.  Then comes the real joy.  You're bringing your own ideas to reality and inspiring others with what you can do!  And you help out the beginner because you remember what it was like the first time reading those detailed instructions for that simple meal.  

Programming is a lot like cooking.  It is learned in the same way.  Day by day it doesn't feel like you are getting any better but look back over the last year or two and you can see you've learned things you used to only dream about.  Now you laugh when you look back at some of your old code you thought was unbelievably clever at the time.  That compiler error that had you tearing your hair out for an entire weekend once, you can now fix in a matter of seconds. Every program you write is a little more sophisticated than the last.  Of course, there were still those programs that were abandoned because right as things were starting to look good, they got way too far out of control.  It's all a part of the process.

Keep learning

I haven't met many people who say they can't cook at least a simple meal.  Why do I keep running in to people that say they could never create software?  It just takes time and determination.  You just have to sit down and do it.  Yet I see so many posts with the titles of "Is it too late for me to start programming?", "Can a man in their 50's learn to create a web page?".  The answer is that it is never too late.  Is it too late to learn how to poach an egg?  No.  Can a man in their 50's learn how to make a pot roast?  Yes.  Stop putting it off and sit down and do it.

I didn't start programming until I was 22.  I was terrified of it actually.  I was in school to be an engineer and I had to take an introductory programming class in the upcoming semester.  The only exposure I had to writing software was when I was really young, maybe 10 or 11.  My dad showed me a simple C program because thought I might be interested in coding.  As smart as he was, my dad was never supposed to be a teacher.  He was a brilliant man, but as with many brilliant people, they forget what it was like to be a beginner.  They forget that some things of the things that are so trivial now pose the biggest obstacle to the newcomer.  So after an hour of watching this text on screen cause this other text to turn a different color, I was thoroughly confused, disappointed, and wanted absolutely nothing to do with this horrific topic.  

So now I had to take this class.  I bought a C++ for dummies book and went to town on it.  I spent every night of a winter break learning how to use variables and functions, how to create a program that converted Fahrenheit to Clausius and back again.  I didn't want that horrific experience again.  And the class wasn't horrific.  In fact I got an A.  I sat down, did the work, figured out the parts that went wrong, asked questions when I got confused, and just did it.  How is that different from learning any other skill?

For an entrepreneur, having at least a little knowledge of programming is essential.  Even if you're not going to do the coding yourself, it's important to know what can be done with it.  I can't tell you how many people I've met that when I tell them what a piece of software can do for them, they respond with "I didn't know that was possible!".  I have saved hours each day at jobs by automating simple tasks.  And this was usually done with programs that were no longer than fifty lines.  That's when I found out what I really wanted to do.

Enter Android

My passion has become Android programming.  Why?  Because it is a perfect combination of resources, accessibility, and practicality, along with a little fun, too.    I just published my first app a few months ago and I love seeing that another person has downloaded my app.  I have created something and shared it with the world.  But it wasn't easy.  It took three years of failed attempts before I landed on something I actually could finish. Maybe failed isn't the right word.  A lot of my previous apps just weren't app store worthy.  I created a lot of apps that I personally used that just weren't polished enough to publish.  I'm not saying that out of modesty, they really weren't finished.  They were buggy, had features that wouldn't work, and were visually displeasing.  The problem was that I would get really excited about an idea so I would start programming it.  There would be a couple features I needed to implement that took a little longer to learn than I had expected.  Then another feature would pop up that I didn't know how to do so I would have to learn something else.  Inevitably, I would let the frustration take over and abandon the project, telling myself that I just wasn't meant to create an Android app.  

That couldn't be farther from the truth.  First of all, most people don't even get as far as a failed attempt because they don't even try. Second, you learn a lot more by your failures than you do your successes.  The first time I made macaroni and cheese, I forgot to drain the water from the noodles before I added the cheese.  Don't laugh, I was young (not that young).  If I would have told myself then that I was never supposed to cook, I would be a very hungry and/or poor man today.  And let me tell you, I can make some mean mac n' cheese today.  The best thing you can do is learn from your failure and try again.  

Android is a great platform to learn on, fail on, succeed on, and keep going because of it's awesome community and abundance of helpful resources.  That's why I develop Android apps and teach Android programming.  The thing that sets me apart is that I teach the hard stuff.  Everybody and their brother has a tutorial about getting started with Android and I am no exception.  But when the beginner tutorials end, it's difficult to find quality resources to learn from about the harder topics like providing services or streaming content.  That is what I aim to solve.  So after asking if it's possible to become an Android developer, the next question might be, "is it worth it?".

Let's do the math

Near the end of 2015, there were over 1.4 billion Android users that accounted for over 53% of mobile devices.  That is an insane amount of technology.  The internet is a fascinating place and never has it been easier to get your ideas out to the world.  The best part is that you need only need a tiny chunk of that 1.4 billion to make even a meager profit.  Say you have an app that sells for $2.99 and you want to make an extra $1000 a month.  That's 335 downloads per month.  That's 0.000024% of the Android user population!  That's it!  You only need a relatively few amount of customers to make even a little extra income each month.  

Obviously, there is no guarantee that you can just write an app and have it take off.  Rovio only found success with Angry Birds after 51 previous attempts at other games.  51 tries!  That means they put in work, time, and effort only to have it not go as planned.  Then they got up and tried again.  Did I mention they did that 51 times?  Giving up so early is the easy way out.  Success belongs to the one's who don't let failures get to them.  Let's apply the Pareto Principle here.  The Pareto Principle states that roughly 80% of the results come from 20% of the work.  Now let's apply this to writing apps.  If your first app doesn't work out, you need to try at least four more times before you give up.  The one that matters just might not have been written yet.  

Anything can be learned.  And anything learned can be improved upon.  You just have to want it and be willing to put in the work.  If people say it's not possible, prove them wrong.  If you hear that it's too late for you to accomplish something, prove them wrong.  Even when it comes to developing software.

Instead of asking if you can be a programmer, or a chef for that matter, try one thing first.  Start.  

How does Gradle Work for Android Apps?

What is gradle

What is it?

If you’ve ever used Android Studio, you’ve no doubt seen the word Gradle thrown all over.  It’s one of those things that seems really important even though you don’t know much about it.  And if you are anything like me, you kind of just hope it will keep working…whatever it is.  I’m going to clear up what Gradle is, why it is so important, and why you don’t need to live in fear of it anymore.

What is it?

According to Wikipedia,

Gradle is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL)…”

While accurate, it’s still a little cryptic and it sure doesn’t make Gradle look any less scary.  Let’s break this down further.

Gradle is open source

Open source simply means that the source code that makes up the program is available for free to whoever wants it and they can do whatever it is they want with it.  This is as opposed to closed source which is what commercial software is; the code is private to the company that created it.

Gradle is a build automation system…

In software, a build is just as it is in any other part of life; the construction of a tangible object.  But in software development, the tangible product is the piece of software which is made of many other files like the source code.  When put together in the correct order, these files come together to make an executable program, more commonly known as an app.

With just a build system, the developer has to manually compile all of the files.  This isn’t so much of a task with small programs with just a few source files, but as programs grow larger and larger and require more resources like images, sounds, screen layouts, etc., it becomes a lot of work to compile a program.  This is where the automation comes in to play.

Believe it or not, a lot of work goes in to combining all of these files to make a program run.  And before these processes could be automated, instructions had to be written by the developer on how to compile the program and this was not done with a nice code editor like Android Studio.  By automating this process, human error is removed and production time is greatly sped up.  Think how many times you hit that play button in a single sitting!

…Builds upon the concepts of Apache Ant and Apache Maven…

Ant is a command-line build system written in java that can be used to build non java applications like C or C++.

Maven is another build automation system meant for any java based project.  Maven’s main goals are to create easy, uniform build systems in the most productive way possible.  Sounds pretty good right?

So basically we have these two tried and true systems that build java apps, now let’s make Gradle improve on them.

…Introduces a Groovy-type…

Groovy, like java, is an object oriented programming language that is meant to work with other java code and libraries.  It omits the commonly used parentheses and periods from java syntax which results in a very human readable context.

…domain specific language (DSL)…

A domain specific language is a programming language made for a specific purpose which in this case is Android development.  So a Groovy-type domain specific language means an object oriented programming language made specifically for the Android platform.  Kind of cool, huh?

So if we were to make the Wikipedia definition simpler, we could say that Gradle is a tool that creates our app using all of the files we have created for it based on methods proven to work by similar tools before it.

That’s a little easier right?

Why two Gradle files?

1I’m sure you’ve noticed by now that there are two Gradle files inside of you Android Studio project, one with the description of “Project” and one with the description of “Module”.  When you start your Android Studio project, you start it with one module.  A single Android studio project can have multiple modules.  Therefore the Project Gradle file are the build instructions for the whole app and the Module Gradle file are the build instructions for just one module of your app.







Hopefully that clears up a little bit about what Gradle is.  It doesn’t have to be as scary as you may think it is and maybe now you’ll have an introductory understanding in why it is there.  However there are all sorts of things you can do with it.  Configuring Gradle builds allows you to create free and paid versions of your app, debug and release versions, and much more.  But alas, that is content for another day.


5 Things I Learned After Publishing My First App

I recently just published my first app, Don't Forget It.  The purpose of the app is to be able to quickly log all of those little tasks that come up throughout the day, picking up your prescription, calling a friend on the way home from work, things like that.  It came to me out of necessity.  I have a terrible memory and I have to do something about it.  It was an amazing process to go from a blank program to a fully working app but I could have made the last six months a little easier if I kept these things in mind.

1. It will never be perfect

It seemed that when I started the app, I had a very clearly defined goal of what I wanted the app to do.  As I continued writing it, I kept thinking of new features to add.  Some of the ideas were better than others but I was starting to lose the main focus of the app: log those tasks QUICKLY.  So I had to pick and choose which features to keep and which to get rid of.  But the real trouble lies underneath.  I am a team of one so with every feature that gets added, there is added time for implementation, testing, debugging, more testing, and so on.  I had to focus on that MVP (Minimum Viable Product) and get the app out the door.  There will be plenty of time to add the features later.  Having an app in the app store, especially the first one, is already a huge win.

2. Test test test

I almost published the app a month ahead of the actual date and that would have been a horrible thing.  I was antsy.  I just wanted to get it done already.  Late nights and early morning programming sessions were starting to wear on me and I was in a hurry.  But lucky for me, I am a little too much of a perfectionist.  I tested the app on my own phone for about two weeks every day before I even gave it to a friend to test.  And it was good that I did.  Software these days is held to an incredibly high standard.  How many times have you used an app or webpage, found one unresponsive feature, or something that just didn't work and said "I'm not coming back".  I sure have.  Take time to test.

3. You need some graphics

For some reason I forgot that once the app was ready to publish, I'd still need promotional material.  A few images at a bare minimum.  It's quick and easy but before you get blindsided by anything, make sure you have these ready to when you publish your app to the Google Play store.

  • At least five screen shots
  • Hi-res icon: 512 x 512, 32-bit PNG (with alpha)
  • Feature Graphic: 1024 wide x 500 high, JPG or 24-bit PNG (no alpha)
  • Promo Graphic: 180 wide x 120 high, JPG or 24-bit PNG (no alpha)
  • TV Banner: 1280 wide x 720 high, JPG or 24-bit PNG (no alpha)

And if you can do it, a little promo video is a great idea as well.

4. It's not as hard as it sounds

Honestly, it's not.  Persistence is the key.  Just don't give up.  Yes, there are plenty of apps in the app store.  Yes, there are a lot of scary statistics telling you odds of being the next Facebook are pretty low.  But you miss 100% of the shots you don't take (Wayne Gretzky).  You also don't make 100% of the shots you take.  More shots, more chances.  And just the feeling of having something in the world that anybody, anywhere can see is an amazing feeling.

5. Tell Everyone you know

I'm not big on self promotion.  In fact, I hate it.  But a little encouragement can go a long way.  It was about two weeks before I made a Facebook post about my app but when I did, the results were amazing.  Not amazing in the sense that it put Don't Forget It on the map, but amazing in the sense that a lot of my friends were happy for me.  They downloaded my app, gave me feedback, and just made me feel like waking up at 5 in the morning to program before work was kind of worth it. 
It's a long ride but well worth it.  I hope this serves as a little encouragement for someone looking to get into app development, or maybe needs a kick in the butt to finish theirs.  Good luck!