私の Android プロジェクトでは、証明書ファイルをプロジェクトのraw/
フォルダーの下にraw/mycert.p12
.
X509Certificate
次に、次のようにしてインスタンスを取得しようとします。
//Get input stream of mycert.p12, the input stream is not null
InputStream inputStream = mContext.getResources().openRawResource(com.my.app.R.raw.mycert);
//Get an instance of CertificateFactory
CertificateFactory cf = CertificateFactory.getInstance("X.509");
//Get buffered input stream
InputStream bis = new BufferedInputStream(inputStream);
//Generate certificate instance
//NullpointerException here...
X509Certificate cert = (X509Certificate) cf.generateCertificates(bis);
また、この証明書 (mycert.p12) を手動でインストールしようとしましたが、x.509 タイプの証明書であると確信しています。
しかし、入力ストリームからインスタンスを生成するときにNullpointerExceptionが発生するのはなぜですか?