我在一个用于 android 应用程序的库中工作,我正在尝试使用 string.xml 将一些消息放在用户的关键点中。
我的问题是,当我在一个 android 测试应用程序中测试库以查看工作流程并达到我显示一条消息(在这种情况下是在日志中)发生致命错误和应用程序崩溃的地步时。
我认为这与string.xml
测试应用程序中的冲突并覆盖了string.xml
我在库中的。这可以通过某种方式解决,还是我强制使用测试应用程序 string.xml 与库一起锻炼?
我是否必须让我的类从 Activity 扩展才能使用 getResources()?或者是访问 string.xml 的任何其他方式,我将留下代码和日志。
代码
public void createCertificateLogTxt(){
File certificado = new File (this.KeyFolderContainer.getAbsoluteFile(),"certificadoLog.txt");
if(!certificado.exists()){
try {
certificado.createNewFile();
this.CertificadoLog = certificado;
Log.i(LOGFILE, "certificadoLog.txt Creado"+ this.getResources().getString(R.string.app_name));
} catch (IOException e) {
Log.e(LOGFILE, "No se puede crear certificadoLog.txt"+ R.string.LOGFILE, e);
}
}
日志
09-14 02:41:24.032: I/Choreographer(23748): Skipped 105 frames! The application may be doing too much work on its main thread.
09-14 02:41:25.593: D/AndroidRuntime(23748): Shutting down VM
09-14 02:41:25.593: W/dalvikvm(23748): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
09-14 02:41:25.753: E/AndroidRuntime(23748): FATAL EXCEPTION: main
09-14 02:41:25.753: E/AndroidRuntime(23748): java.lang.IllegalStateException: Could not execute method of the activity
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.view.View$1.onClick(View.java:3633)
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.view.View.performClick(View.java:4240)
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.view.View$PerformClick.run(View.java:17721)
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.os.Handler.handleCallback(Handler.java:730)
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.os.Handler.dispatchMessage(Handler.java:92)
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.os.Looper.loop(Looper.java:137)
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-14 02:41:25.753: E/AndroidRuntime(23748): at java.lang.reflect.Method.invokeNative(Native Method)
09-14 02:41:25.753: E/AndroidRuntime(23748): at java.lang.reflect.Method.invoke(Method.java:525)
09-14 02:41:25.753: E/AndroidRuntime(23748): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-14 02:41:25.753: E/AndroidRuntime(23748): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-14 02:41:25.753: E/AndroidRuntime(23748): at dalvik.system.NativeStart.main(Native Method)
09-14 02:41:25.753: E/AndroidRuntime(23748): Caused by: java.lang.reflect.InvocationTargetException
09-14 02:41:25.753: E/AndroidRuntime(23748): at java.lang.reflect.Method.invokeNative(Native Method)
09-14 02:41:25.753: E/AndroidRuntime(23748): at java.lang.reflect.Method.invoke(Method.java:525)
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.view.View$1.onClick(View.java:3628)
09-14 02:41:25.753: E/AndroidRuntime(23748): ... 11 more
09-14 02:41:25.753: E/AndroidRuntime(23748): Caused by: java.lang.NullPointerException
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.content.ContextWrapper.getResources(ContextWrapper.java:89)
09-14 02:41:25.753: E/AndroidRuntime(23748): at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)
09-14 02:41:25.753: E/AndroidRuntime(23748): at com.idyseg.movilsecure.files.KeyFileManager.createCertificateLogTxt(KeyFileManager.java:76)
09-14 02:41:25.753: E/AndroidRuntime(23748): at com.idyseg.movilsecure.MSMasterControler.<init>(MSMasterControler.java:34)
09-14 02:41:25.753: E/AndroidRuntime(23748): at com.idyseg.librerytester.MainActivity.Conector(MainActivity.java:33)
09-14 02:41:25.753: E/AndroidRuntime(23748): ... 14 more
09-14 02:41:28.253: I/Process(23748): Sending signal. PID: 23748 SIG: 9