gpt4 book ai didi

java - NoSuchAlgorithmException : MessageDigest SHA implementation not found while ObjectInputStream. readObject() Android

转载 作者:行者123 更新时间:2023-11-30 02:43:25 25 4
gpt4 key购买 nike

我将模型类保存在本地存储中用于缓存目的

我使用以下方法将对象写入文件

private void writeData(Object data, String fileName) {
try {
FileOutputStream fos = context.openFileOutput(fileName,
Context.MODE_PRIVATE);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(data);
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

下面是从文件中读取对象的代码

public Object readData(String fileName) {
Object data = null;
if (context != null) {
try {
FileInputStream fis = context.openFileInput(fileName);
ObjectInputStream is = new ObjectInputStream(fis);
data = is.readObject();
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (StreamCorruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
return data;
}

它运行良好,但在某些设备上它会抛出奇怪的异常即

Caused by: java.security.NoSuchAlgorithmException: MessageDigest SHA implementation not found

我不知道后台发生了什么,readData 是如何抛出 NoSuchAlogorithmException 的,我没有在其中使用任何 MessageDigest。我在 Java 和 Android 文档中搜索了很多关于 ObjectInputStream.readObject() 的信息。我没有得到任何解决方案。

我试图为 NoSuchAlgorithmException 放置 catch 类,但在 eclipse 中它显示为错误

Unreachable catch block for NoSuchAlgorithmException. This exception is never thrown from the try statement body

这里附上完整的崩溃日志

java.lang.Error: java.security.NoSuchAlgorithmException: MessageDigest SHA implement    ation not found
at java.io.ObjectStreamClass.computeSerialVersionUID(ObjectStreamClass.java:420)
at java.io.ObjectStreamClass.cre ateClassDesc(ObjectStreamClass.java:259)
at java.io.ObjectStreamClass.lookupStreamClass(ObjectStreamClass.java:1069)
at java.io.ObjectInputStream.verifyAndInit(ObjectInputStream.java:2375)
at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1662)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:683)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1803)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
at java.util.ArrayList.readObject(ArrayList.java:657)
at java.lang.reflect.Method.invokeN ative(N ative Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1354)
at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
at com.test.util.CacheManager.readD ata(CacheManager.java:104)
at com.test.SplashActivity.onCre ate(SplashActivity.java:178)
at android.app.Activity.performCre ate(Activity.java:5206)
at android.app.Instrument ation.callActivityOnCre ate(Instrument ation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.disp atchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeN ative(N ative Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.N ativeStart.main(N ative Method)
Caused by: java.security.NoSuchAlgorithmException: MessageDigest SHA implement ation not found
at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:177)
at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:151)
at java.security.MessageDigest.getInstance(MessageDigest.java:91)
at java.io.ObjectStreamClass.computeSerialVersionUID(ObjectStreamClass.java:418)
... 42 more
java.security.NoSuchAlgorithmException: MessageDigest SHA implement ation not found
at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:177)
at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:151)
at java.security.MessageDigest.getInstance(MessageDigest.java:91)
at java.io.ObjectStreamClass.computeSerialVersionUID(ObjectStreamClass.java:418)
at java.io.ObjectStreamClass.cre ateClassDesc(ObjectStreamClass.java:259)
at java.io.ObjectStreamClass.lookupStreamClass(ObjectStreamClass.java:1069)
at java.io.ObjectInputStream.verifyAndInit(ObjectInputStream.java:2375)
at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1662)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:683)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1803)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
at java.util.ArrayList.readObject(ArrayList.java:657)
at java.lang.reflect.Method.invokeN ative(N ative Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1354)
at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
at com.test.util.CacheManager.readD ata(CacheManager.java:104)
at com.test.SplashActivity.onCre ate(SplashActivity.java:178)
at android.app.Activity.performCre ate(Activity.java:5206)
at android.app.Instrument ation.callActivityOnCre ate(Instrument ation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.disp atchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeN ative(N ative Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.N ativeStart.main(N ative Method)

编辑

这是我尝试编写和阅读的类。我使用的内部类 AutoPromoData、OrderBkgPixData SubscriptionUrlData 等都在此类内部,包含用于索引和 url 的简单 int 和字符串。

配置.jvaa

import java.util.ArrayList;

import com.google.gson.annotations.SerializedName;
import com.test.model.CacheTimeData;
import com.test.SplashUrlData;
import com.test.SubscriptionUrlData;

public class Configuration {

int version;

@SerializedName("pivotCodeRetour")
int pivotCodeRetour;

ArrayList<WSTimeOutData> WSTimeOut;
ArrayList<AutoPromoData> AutoPromo;
ArrayList<StreetMktData> StressMkt;
ArrayList<OrderBkgPixData> OrderBkgPix;
ArrayList<LogBkgPixData> LogBkgPix;
ArrayList<SubscriptionUrlData> SubscriptionBkgPix;

String Voucher;
ArrayList<PhoneContactData> PhoneContact;
String ProdAvailability;
String PaymentUrl;
String TravSaleHomeUrl;
String TravCartUrl;
String TravOrderDetailUrl;
String TicketSaleHomeUrl;
String TicketOrderUrl;
String CGV;
String wishlist;

int pushCart;
int pushVoucher;

ArrayList<SplashUrlData> Splashscreen;
ArrayList<CacheTimeData> CacheTime;

public int getPushCart() {
return pushCart;
}

public ArrayList<SubscriptionUrlData> getSubscriptionBkgPix() {
return SubscriptionBkgPix;
}

public void setSubscriptionBkgPix(
ArrayList<SubscriptionUrlData> subscriptionBkgPix) {
SubscriptionBkgPix = subscriptionBkgPix;
}

public void setPushCart(int pushCart) {
this.pushCart = pushCart;
}

public int getPushVoucher() {
return pushVoucher;
}

public void setPushVoucher(int pushVoucher) {
this.pushVoucher = pushVoucher;
}

public int getVersion() {
return version;
}

public void setVersion(int version) {
this.version = version;
}

public ArrayList<WSTimeOutData> getWSTimeOut() {
return WSTimeOut;
}

public void setWSTimeOut(ArrayList<WSTimeOutData> wSTimeOut) {

WSTimeOut = wSTimeOut;
}

public ArrayList<AutoPromoData> getAutoPromo() {
return AutoPromo;
}

public void setAutoPromo(ArrayList<AutoPromoData> autoPromo) {
AutoPromo = autoPromo;
}

public ArrayList<StreetMktData> getStressMkt() {
return StressMkt;
}

public void setStressMkt(ArrayList<StreetMktData> stressMkt) {
StressMkt = stressMkt;
}

public ArrayList<OrderBkgPixData> getOrderBkgPix() {
return OrderBkgPix;
}

public void setOrderBkgPix(ArrayList<OrderBkgPixData> orderBkgPix) {
OrderBkgPix = orderBkgPix;
}

public ArrayList<LogBkgPixData> getLogBkgPix() {
return LogBkgPix;
}

public void setLogBkgPix(ArrayList<LogBkgPixData> logBkgPix) {
LogBkgPix = logBkgPix;
}

public String getVoucher() {
return Voucher;
}

public void setVoucher(String voucher) {
Voucher = voucher;
}

public ArrayList<PhoneContactData> getPhoneContact() {
return PhoneContact;
}

public void setPhoneContact(ArrayList<PhoneContactData> phoneContact) {
PhoneContact = phoneContact;
}

public String getProdAvailability() {
return ProdAvailability;
}

public void setProdAvailability(String prodAvailability) {
ProdAvailability = prodAvailability;
}

public String getPaymentUrl() {
return PaymentUrl;
}

public void setPaymentUrl(String paymentUrl) {
PaymentUrl = paymentUrl;
}

public String getTravSaleHomeUrl() {
return TravSaleHomeUrl;
}

public void setTravSaleHomeUrl(String travSaleHomeUrl) {
TravSaleHomeUrl = travSaleHomeUrl;
}

public String getTravCartUrl() {
return TravCartUrl;
}

public void setTravCartUrl(String travCartUrl) {
TravCartUrl = travCartUrl;
}

public String getTravOrderDetailUrl() {
return TravOrderDetailUrl;
}

public void setTravOrderDetailUrl(String travOrderDetailUrl) {
TravOrderDetailUrl = travOrderDetailUrl;
}

public String getTicketSaleHomeUrl() {
return TicketSaleHomeUrl;
}

public void setTicketSaleHomeUrl(String ticketSaleHomeUrl) {
TicketSaleHomeUrl = ticketSaleHomeUrl;
}

public String getTicketOrderUrl() {
return TicketOrderUrl;
}

public void setTicketOrderUrl(String ticketOrderUrl) {
TicketOrderUrl = ticketOrderUrl;
}

public ArrayList<SplashUrlData> getSplashscreen() {
return Splashscreen;
}

public void setSplashscreen(ArrayList<SplashUrlData> splashscreen) {
Splashscreen = splashscreen;
}

public ArrayList<CacheTimeData> getCacheTime() {
return CacheTime;
}

public void setCacheTime(ArrayList<CacheTimeData> cacheTime) {
CacheTime = cacheTime;
}

public int getPivotCodeRetour() {
return pivotCodeRetour;
}

public void setPivotCodeRetour(int pivotCodeRetour) {
this.pivotCodeRetour = pivotCodeRetour;
}

public String getCGV() {
return CGV;
}

public void setCGV(String cGV) {
CGV = cGV;
}

public String getWishlist() {
return wishlist;
}

public void setWishlist(String wishlist) {
this.wishlist = wishlist;
}
}

最佳答案

这是针对相关设备的错误报告,但您可以通过始终在可序列化类中定义自己的 serialVersionUID 来避免它,出于其他原因无论如何您都应该这样做。当 Java 为这个缺失的类属性创建默认值时,就会发生这种情况。

关于java - NoSuchAlgorithmException : MessageDigest SHA implementation not found while ObjectInputStream. readObject() Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25447804/

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