Java 不传递数据的意图
我的意图是传递一个从当月当天开始的Java 不传递数据的意图,java,android,Java,Android,我的意图是传递一个从当月当天开始的整数。但当我把它打印到excel表格时,它是空白的 这是我的第一堂课,它得到了一个月的第几天,并把它转换成int-day int day = datepicker.getDayOfMonth(); Intent intent = new Intent (OneWeekPlan.this, Save_File.class); intent.putExtra("day", day); intent.putExtra("wk1month", month); inte
整数。但当我把它打印到excel表格时,它是空白的
这是我的第一堂课,它得到了一个月的第几天,并把它转换成int-day
int day = datepicker.getDayOfMonth();
Intent intent = new Intent (OneWeekPlan.this, Save_File.class);
intent.putExtra("day", day);
intent.putExtra("wk1month", month);
intent.putExtra("wk1year", year);
intent.putExtra("wk1dayofweek", wk1dayofweek);
startActivity(intent);
下面是接受该输入的类
private boolean saveExcelFile(Context context, String fileName) {
// check if available and not read only
if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
Log.e(TAG, "Storage not available or read only");
return false;
}
boolean success = false;
String day = getIntent().getStringExtra("day");
//New Workbook
Workbook wb = new HSSFWorkbook();
Cell c1 = null;
Cell c2 = null;
Cell c3 = null;
Cell c4 = null;
Cell c5 = null;
Cell c6 = null;
Cell c7 = null;
Cell c8 = null;
Cell c9 = null;
//Cell style for header row
CellStyle cs = wb.createCellStyle();
//New Sheet
Sheet sheet1 = null;
sheet1 = wb.createSheet("My PT Plan");
// Generate column headings
Row row1 = sheet1.createRow(0);
//Create First Row that holds dates
c1 = row1.createCell(0);
c1.setCellValue("");
c1.setCellStyle(cs);
c1 = row1.createCell(1);
c1.setCellValue(day);
c1.setCellStyle(cs);
c1 = row1.createCell(2);
c1.setCellValue(day);
c1.setCellStyle(cs);
c1 = row1.createCell(3);
c1.setCellValue(day);
c1.setCellStyle(cs);
c1 = row1.createCell(4);
c1.setCellValue(day);
c1.setCellStyle(cs);
c1 = row1.createCell(5);
c1.setCellValue(day);
c1.setCellStyle(cs);
//Set width of columns for first row
sheet1.setColumnWidth(0, (15 * 300));
sheet1.setColumnWidth(1, (15 * 300));
sheet1.setColumnWidth(2, (15 * 300));
sheet1.setColumnWidth(3, (15 * 300));
sheet1.setColumnWidth(4, (15 * 300));
sheet1.setColumnWidth(5, (15 * 300));
// Create a path where we will place our List of objects on external storage
File file = new File(context.getExternalFilesDir(null), fileName);
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
wb.write(os);
Log.w("FileUtils", "Writing file" + file);
success = true;
} catch (IOException e) {
Log.w("FileUtils", "Error writing " + file, e);
} catch (Exception e) {
Log.w("FileUtils", "Failed to save file", e);
} finally {
try {
if (null != os)
os.close();
} catch (Exception ex) {
}
}
return success;
}
我确信int-day没有任何价值,但我正试图找出原因。谢谢。天是int值使用getIntExtra而不是getStringExtra获取int值:
int day = getIntent().getIntExtra("day",0);
查看以下检查:
Try Intent.hasExtra(字符串名称)
检查是否传递了额外信息
在将值传递给:intent.putExtra(“day”,day)
您已经提出了类似的问题:
我已经回答了。您可以使用SharedReferences
,而不是使用Intent
传递数据。这在每节课上都有效。在第一个活动中
int day = datepicker.getDayOfMonth();
Intent intent = new Intent (OneWeekPlan.this, Save_File.class);
intent.putExtra("day", day);
intent.putExtra("wk1month", month);
intent.putExtra("wk1year", year);
intent.putExtra("wk1dayofweek", wk1dayofweek);
startActivity(intent);
秘密活动
int day = getIntent().getExtra().getInt("day");
int month= getIntent().getExtra().getInt("wk1month");
int year= getIntent().getExtra().getInt("wk1year");
int wk1dayofweek= getIntent().getExtra().getInt("wk1dayofweek");
尝试使用:getIntent().getIntExtra(“day”,0)获取int值。在通过intent发送到值之前打印值,然后识别您自己。@Hareshchelana,您是对的,基本数据类型之间有很多混淆。。当然是imma dummy。谢谢=)当我这样做时,我的变量显示为0。我希望它传递来自原始类的值。当我把它放在变量名上时,比如int day=getIntent().getIntExtra(“day”,day);我得到一个错误,当我这样做时,它为变量打印出0。我希望它将var的值传递给另一个类int day=getIntent().getIntExtra(“day”,day);但是我得到了一个错误,这是有效的,但是我必须把int-day=getIntent().getExtras().getInt(“day”)getExtra必须是复数。Eclipse帮我抓住了它。但是谢谢!