Android Exception NameNotFoundException

I do not understand why this exception occurs.

In my main activity in the onCreate method, I have this code first:

try { PackageInfo info = this.getPackageManager().getPackageInfo("com.mypacket", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.e("Hash", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (NameNotFoundException e) { Log.e("Hash", "Error: NameNotFoundException"); e.printStackTrace(); } catch (NoSuchAlgorithmException e) { Log.e("Hash", "Error: NoSuchAlgorithmException"); } 

An exception is a NameNotFoundException, I want to solve it because I think this is causing problems with the Facebook SDK.

Thanks to everyone.

If this helps, this is my AndroidManifest.xml

  <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myPackageName.app" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" /> <permission android:name="com.myPackageName.app.permission.MAPS_RECEIVE" android:protectionLevel="signature"/> <uses-permission android:name="com.myPackageName.app.permission.MAPS_RECEIVE"/> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="com.myPackageName.app.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.myPackageName.app.permission.C2D_MESSAGE" /> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <application android:name="@string/app_name" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> <receiver android:name=".GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.myPackageName.app" /> </intent-filter> </receiver> <service android:name=".GcmIntentService" /> <activity android:name="com.myPackageName.app.SplashScreen" android:screenOrientation="portrait" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- Google Maps V2 API KEY --> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="apy key" /> </application> </manifest> 
+7
source share
6 answers

You have the wrong name for your package. For security, always use Context.getPackageName() .

 PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackageName(), PackageManager.GET_SIGNATURES); 
+9
source

Your package name is com.myPackageName.app not com.mypacket. BTW you can get the package name Context # getPackageName ()

+2
source

This problem occurs when you create a hash key project and the application for which you create a hash key is not in any workspace / directory, so a NameNotFoundException is thrown.

Greetings :)

0
source

This means that either you are giving the wrong package name, or maybe you are not sure about the package name.

Case 1. If you know about your package name, just cross it.

Case 2. If you are not sure about the name of the package ( this situation may also occur if you did some refactoring of the code, i.e. Rename the package)

There are several approaches to fixing it.

  • the package name is listed at the top of AndroidManifest.xml

enter image description here

  1. If still not allowed to get the package name

    Context.getPackageName ();

or

 Log.d(); 

In Logcat, you must specify the package name of the application column.

0
source

This can also happen if you already have the application installed. For example, if you were to debug your application, then test the release of .apk on the same device without deleting the debug version. If so, just uninstall and the installation should work.

0
source

Uninstall the application from the device, and then run it again through Android Studio. Helps me

0
source

Source: https://habr.com/ru/post/954840/


All Articles