gpt4 book ai didi

java - Android 异常 NameNotFoundException

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:21:41 26 4
gpt4 key购买 nike

我不明白为什么会出现这个异常。

在我的主要 Activity 中,在 onCreate 方法中我首先有这段代码:

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

异常是 NameNotFoundException,我想解决它,因为我认为它会导致 Facebook SDK 出现问题。

谢谢大家

如果有帮助,这是我的 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>

最佳答案

你的包名有误。为了安全起见,请始终使用 Context.getPackageName()

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

关于java - Android 异常 NameNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19068010/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com