Android - Activity Not Found Exception

Android Studio: Activity not found exception when using Intents in ALL programming projects

You can't use context before it's initialized during activity lifecycle. Intents can be created after onCreate()

Move this line sowhere inside listener or some method called when activity is running (create it just before use):

public final Intent intenttest = new Intent(this, SecondActivity.class);

How do I resolve Activity Not Found Exception

The error message says it all,

android.content.ActivityNotFoundException: Unable to find explicit
activity class
{com.virtusync.scanningtool/com.android.example.cameraxbasic.MainActivityKt};
have you declared this activity in your AndroidManifest.xml?

From what it seems in your manifst, you haven't.

The only activity declared is MainActivity

<activity
android:name=".MainActivity"
...

The exception was raised because in your code you are using a class that is named MainActivityKt.

Probably you mispelled that name, fix it.

How to handle the ActivityNotFoundException?

Just simply add that activity in your manifest file..

like,

<activity android:name=".ActivityName"
android:label="@string/app_name">
</activity>

EDIT:

Now to catch the ActivityNOtFoundException put your code in,

try {

// Your startActivity code wich throws exception
} catch (ActivityNotFoundException activityNotFound) {

// Now, You can catch the exception here and do what you want
}

Note: Be careful when you catch this ActivityNotFound Exception but you can't modified manifest file to run time, means once you encountered the exception and if you want to add that this activity tag at runtime then you can't.

android.content.ActivityNotFoundException: Unable to find explicit activity class Android Studio Kotlin Error

Replace:

R.layout.registration::class.java

with:

Registration::class.java

You are attempting to use a resource ID as an Activity class, and that will not work.

ActivityNotFoundException on some Android devices

Operating Systems with this exception are 4.4.4 and 5.0.1

No. You happen to have received crash notices for those OS versions. There are ~2 billion Android devices, and this sort of problem can happen on any of them.

Any ideas for this exception

You are assuming that each and every one of those ~2 billion Android devices have one or more apps with an activity matching Intent.ACTION_MAIN and Intent.CATEGORY_APP_MUSIC. There is no requirement for any of those devices to have such an activity.

proposals to avoid it?

Option #1: Wrap your startActivity() call in a try/catch block and catch the ActivityNotFoundException, then tell the user that you cannot find a suitable app.

Option #2: Use PackageManager and queryIntentActivities() to see if there are any matches for the Intent. If there are none, do not call startActivity(), then tell the user that you cannot find a suitable app.

How to fix android.content.ActivityNotFoundException android-studio 2.3.3

The result when you scan a barcode is often not a valid URL. It is often just a string with several digits. It has no schema or protocol, so it is (very possibly) not defined "what type of resource locator it is". Android's ACTION_VIEW intent is mostly use this information to decide "start which app/activity to open this URL". With a lack of the important information, Android has no idea to open it.

You may specify some cases for handling the result. For example, if the result begins with "http://" or "https://", directly use your code to handle, but if it is just a string of numbers, display it directly, or append it after some string before it is used for Uri.parse, for example "https://google.com/search?q=", to search this barcode's value as you may wanted, or other things you want to do with that 13 digit result.

For example, (the code below written in mobile hasn't been tested, just show the idea):

@Override 
public void onClick(DialogInterface dialog, int which) {
Intent browserIntent;
if (myResult.startsWith("http://") || myResult.startsWith("https://"))
browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myResult));
else
browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://google.com/search?q=" + myResult));
startActivity(browserIntent);
}

ActivityNotFoundException when accessing the camera using registerForActivityResult

Remove the setType() call. And, consider replacing all of this with ActivityResultContracts.TakePicture().

android.content.ActivityNotFoundException:

Maybe you need to check that you added the new activity to the manifest.xml file

Example:

<activity
android:name=".className"
android:label="@string/app_name" >
</activity>


Related Topics



Leave a reply



Submit