Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Exception NameNotFoundException

I don't understand why happens this exception.

In my Main activity, in the method onCreate I have this code at 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");
    }

The exception is NameNotFoundException, I want to solve it because I think it causes problem with the Facebook SDK.

Thank you all.

If 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>
like image 321
Andrea Falzetti Avatar asked Sep 28 '13 14:09

Andrea Falzetti


1 Answers

You got your package name wrong. For safety, always use Context.getPackageName().

PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackageName(), PackageManager.GET_SIGNATURES);
like image 67
Swayam Avatar answered Oct 06 '22 22:10

Swayam