当我包含autosizecloumn()时,如果重新启动我的应用程序,则不会在目录中创建任何文件。如果我为每一列手动使用setColumwidth()则效果很好
我的日志猫:
2019-02-21 22:54:59.448 4410-4410/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
2019-02-21 22:54:59.463 4410-4410/? D/AccessibilityManager: current package=com.example.railway, accessibility manager mIsFinalEnabled=true, mOptimizeEnabled=false, mIsUiAutomationEnabled=false, mIsInterestedPackage=true
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void com.example.railway.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:16)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6845)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1119)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2700)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2808)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1541)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void android.os.Looper.loop() (Looper.java:165)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6375)
2019-02-21 22:54:59.484 4410-4410/com.example.railway I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:912)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:802)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.railway-1/base.apk", zip file "/data/app/com.example.railway-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.railway-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.railway-1/lib/
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:74)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void com.example.railway.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:16)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6845)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1119)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2700)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2808)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1541)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void android.os.Looper.loop() (Looper.java:165)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6375)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:912)
2019-02-21 22:54:59.485 4410-4410/com.example.railway I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:802)
2019-02-21 22:54:59.571 4410-4410/com.example.railway E/HAL: PATH3 /odm/lib64/hw/gralloc.qcom.so
2019-02-21 22:54:59.571 4410-4410/com.example.railway E/HAL: PATH2 /vendor/lib64/hw/gralloc.qcom.so
2019-02-21 22:54:59.571 4410-4410/com.example.railway E/HAL: PATH1 /system/lib64/hw/gralloc.qcom.so
2019-02-21 22:54:59.571 4410-4410/com.example.railway E/HAL: PATH3 /odm/lib64/hw/gralloc.msm8953.so
2019-02-21 22:54:59.571 4410-4410/com.example.railway E/HAL: PATH2 /vendor/lib64/hw/gralloc.msm8953.so
2019-02-21 22:54:59.571 4410-4410/com.example.railway E/HAL: PATH1 /system/lib64/hw/gralloc.msm8953.so
我的代码
public class Excel {
public boolean saveExcelFile(Context context,String filename) {
// check if available and not read only
if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
Log.d("FileUtils", "Storage not available or read only");
return false;
}
boolean success = false;
//New Workbook
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet");
//BEggining of heading
Row rowhead = sheet.createRow(9);
Cell cell1 = rowhead.createCell( 0);
Cell cell2 = rowhead.createCell( 1);
Cell cell3 = rowhead.createCell( 2);
Cell cell4 = rowhead.createCell( 3);
Cell cell5 = rowhead.createCell( 4);
Cell cell6 = rowhead.createCell( 5);
Cell cell7 = rowhead.createCell( 6);
Cell cell8 = rowhead.createCell( 7);
Cell cell9 = rowhead.createCell(8);
cell1.setCellValue("DATE");
cell2.setCellValue("TRAIN NO");
cell3.setCellValue("LOCO NO");
cell4.setCellValue("From");
cell5.setCellValue("TO");
cell6.setCellValue("COD/DEP");
cell7.setCellValue("ARR");
cell8.setCellValue("LOCOPILOT");
cell9.setCellValue("REMARKS");
// head file
Row row = sheet.createRow(1);
Cell cell = row.createCell(0);
cell.setCellValue("SOUTH CENTRAL RAILWAY \n VIJAYAWDA\n DAILYWISE STATEMENT FOR THE MONTH OF"+filename+
"\nNAME:G.SRNIVASA RAO DESIGN:CLI HQRS:RJY \nPF.NO:09327885 PAY:Rs.88700");
CellStyle cs = wb.createCellStyle();
cs.setVerticalAlignment(VerticalAlignment.CENTER);
cs.setWrapText(true);
cell.setCellStyle(cs);
row.setHeightInPoints((5*sheet.getDefaultRowHeightInPoints()));
sheet.addMergedRegion(new CellRangeAddress(1,4,0,9));
CellUtil.setAlignment(cell, HorizontalAlignment.CENTER);
// end of head file
for (int i =0 ;i< 9;i++)
{
sheet.autoSizeColumn(i,true);
}
// Create a path where we will place our List of objects on external storage
File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS),filename+".xls");
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
wb.write(os);
Log.d("FileUtils", "Writing file" + file);
success = true;
} catch (IOException e) {
Log.d("FileUtils", "Error writing " + file, e);
} catch (Exception e) {
Log.d("FileUtils", "Failed to save file", e);
} finally {
try {
if (null != os)
os.close();
} catch (Exception ex) {
}
}
return success;
}
public static boolean isExternalStorageReadOnly() {
String extStorageState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) {
return true;
}
return false;
}
public static boolean isExternalStorageAvailable() {
String extStorageState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(extStorageState)) {
return true;
}
return false;
}
}
尽管最初是由于合并的单元格,所以删除并再次尝试后仍在重新启动应用程序且未创建文件的情况。 在互联网上搜索时,有一些结果提到它是因为“字体”的缘故,所以甚至尝试了一下,如果我将字体设置为arial,则再次加粗的应用会在没有文件创建的情况下重新启动
apache的新手 如果代码中有任何错误或更好的解决方法,请纠正我
预先感谢:)