小编lui*_*ero的帖子

如何使用括号表示法检查打字稿中的无效性

我想检查对象内的数组是否存在、不为空且不为空

我需要用括号表示法引用该属性。

我的对象

profile = {
    myArray: [1,2,3]
}
Run Code Online (Sandbox Code Playgroud)

我正在这样检查

const section = "myArray";
if(section in profile && profile[section] && profile[section].length ) { // do something}
Run Code Online (Sandbox Code Playgroud)

我希望这能起作用,但我在这部分收到一个错误profile[section].length,上面写着object is possibly null or undefined

如果我使用点符号来做到这一点,它就可以正常工作

if('myArray' in profile && profile.myArray && profile.myArray.length ) { // do something}
Run Code Online (Sandbox Code Playgroud)

null object typescript

4
推荐指数
1
解决办法
2412
查看次数

当我试图从用相机拍摄的照片中获取Uri时,我得到了null

这是我的问题,当我试图从我拍摄的照片中获取Uri时我会在模拟器和我的设备上使用相机获得null,但是如果我使用其他相机应用程序,只能使用系统相机,总是有效.这是我的代码

用于启动相机应用程序

takePic.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    String captured_image = System.currentTimeMillis() + ".jpg";
    File file = new File(Environment.getExternalStorageDirectory(), captured_image); 
    captured_image = file.getAbsolutePath();
    outputFileUri = Uri.fromFile(file); 
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
    intent.putExtra("return-data", true);
    startActivityForResult(intent, CAMERA_REQUEST);
   }
});
Run Code Online (Sandbox Code Playgroud)

获取图像

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  if (requestCode == CAMERA_REQUEST) { 
    ContentResolver cr = getContentResolver();
    InputStream in = null;
    try 
    {
        in = cr.openInputStream(outputFileUri); 
    } 
    catch (FileNotFoundException e) 
    {
        e.printStackTrace();
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

当活动返回时,outputFileUri始终为null.谢谢.

camera android image save

3
推荐指数
1
解决办法
2919
查看次数

在API 21中以编程方式隐藏DatePicker中的Calendarview

我遇到了与此主题相同的问题:Android Material Design Inline Datepicker问题,但我没有使用XML布局,而是以编程方式构建DatePicker.

这是我正在使用但不起作用的代码

DatePicker dpView = new DatePicker(ctx);
dpView.setCalendarViewShown(false);
dpView.setSpinnersShown(true);
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它发挥作用?

java android datepicker

1
推荐指数
3
解决办法
1万
查看次数

标签 统计

android ×2

camera ×1

datepicker ×1

image ×1

java ×1

null ×1

object ×1

save ×1

typescript ×1