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());
recyclerView.setAdapter(adapter);

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

public MainCardAdapter(Context context)
{
    this.context = context;
}
//...

@Override
public void onClick(View v)
{
    Intent i = new Intent(context, ResumeSectionsActivity.class);
    context.startActivity(i);
}

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);

Leave a Reply

Your email address will not be published. Required fields are marked *