为什么我的provider返回的是空值

代码粉 2019-05-06 11:16:52
package com.example.shiyan8;

import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {
public static final int TAKE_PHOTO = 1;
private ImageView picture;
private Uri imageUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button take_photo = (Button) findViewById(R.id.take_photo);
picture = (ImageView) findViewById(R.id.picture);
take_photo.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
File outputImage = new File(getExternalCacheDir(),
“output_image.jpg”);
try{
if (outputImage.exists()){
outputImage.delete();
}
outputImage.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= 24) {
imageUri = FileProvider.getUriForFile(MainActivity.this,
“com.example.shiyan8.fileprovider”,outputImage);
} else {
imageUri = Uri.fromFile(outputImage);
}
Intent intent = new Intent(“android.media.action.IMAGE_CAPTURE”);
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
startActivityForResult(intent,TAKE_PHOTO);
}
});
}
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
switch (requestCode) {
case TAKE_PHOTO:
if (requestCode == RESULT_OK) {
try{
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
picture.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
break;
default:
break;
}
}
}

这是我的日志

2019-05-06 10:54:24.990 7419-7419/? I/example.shiyan: Not late-enabling -Xcheck:jni (already on)
2019-05-06 10:54:25.105 7419-7419/? W/example.shiyan: Unexpected CPU variant for X86 using defaults: x86
2019-05-06 10:54:25.767 7419-7419/com.example.shiyan8 W/example.shiyan: JIT profile information will not be recorded: profile file does not exits.
2019-05-06 10:54:25.769 7419-7419/com.example.shiyan8 I/chatty: uid=10087(com.example.shiyan8) identical 10 lines
2019-05-06 10:54:25.775 7419-7419/com.example.shiyan8 W/example.shiyan: JIT profile information will not be recorded: profile file does not exits.
2019-05-06 10:54:25.822 7419-7419/com.example.shiyan8 I/InstantRun: starting instant run server: is main process
2019-05-06 10:54:26.257 7419-7419/com.example.shiyan8 W/example.shiyan: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-05-06 10:54:26.258 7419-7419/com.example.shiyan8 W/example.shiyan: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-05-06 10:54:26.323 7419-7419/com.example.shiyan8 D/OpenGLRenderer: HWUI GL Pipeline
2019-05-06 10:54:26.397 7419-7441/com.example.shiyan8 I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-05-06 10:54:26.399 7419-7441/com.example.shiyan8 I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-05-06 10:54:26.400 7419-7441/com.example.shiyan8 I/OpenGLRenderer: Initialized EGL, version 1.4
2019-05-06 10:54:26.402 7419-7441/com.example.shiyan8 D/OpenGLRenderer: Swap behavior 1
2019-05-06 10:54:26.404 7419-7441/com.example.shiyan8 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without…
2019-05-06 10:54:26.404 7419-7441/com.example.shiyan8 D/OpenGLRenderer: Swap behavior 0
2019-05-06 10:54:26.422 7419-7441/com.example.shiyan8 D/EGL_emulation: eglCreateContext: 0xec405360: maj 2 min 0 rcv 2
2019-05-06 10:54:26.462 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 10:54:26.578 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:03:13.991 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:03:25.954 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:03:31.799 7419-7441/com.example.shiyan8 I/OpenGLRenderer: Davey! duration=1152ms; Flags=2, IntendedVsync=2812437912774, Vsync=2812437912774, OldestInputEvent=0, NewestInputEvent=0, HandleInputStart=2812437912774, AnimationStart=2812437912774, PerformTraversalsStart=2812437912774, DrawStart=2812437912774, SyncQueued=2812451718200, SyncStart=2812451795600, IssueDrawCommandsStart=2812471354900, SwapBuffers=2813565789400, FrameCompleted=2813590707400, DequeueBufferDuration=79000, QueueBufferDuration=223000,
2019-05-06 11:03:31.820 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:03:42.538 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:04:09.046 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:04:19.975 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:04:33.822 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:04:42.054 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
---------------------
作者:qq_43620227
来源:CSDN
原文:https://blog.csdn.net/qq_43620227/article/details/89878402
版权声明:本文为博主原创文章,转载请附上博文链接!
...全文
107 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
这是一款轻量级的MyBatis插件,在GitHub上发布的有打好的jar包,25.2Kb,导入项目中即可使用,支持创建数据表、自定义查询、分页查询等常用的数据库操作。 依赖包 org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.2 mysql mysql-connector-java runtime 目录结构 mybatis:MyBatis 通用 Mapper 相关 annotation:注解相关 FieldAttribute.java:字段注解,标示成员变量为数据库字段,并设置相应的约束信息,如:长度、非空、查询字段、索引字段等 KeyAttribute.java:主键注解,标示成员变量为主键,支持标注为自增主键 SortAttribute.java:排序注解,标示成员变量为排序字段 TableAttribute.java:数据表注解,标示实体类对应的表名称、说明信息 provider:Sql 语句生成相关 BaseCreateProvider.java:数据表创建语句的生成器,支持生成索引 BaseDeleteProvider.java:delete 语句生成器,支持根据 ID、主键、自定义条件删除 BaseInsertProvider.java:insert 语句生成器,支持自增主键的 insert 操作 BaseSelectProvider.java:select 语句生成器,支持分页查询、统计查询、自定义条件查询等 BaseUpdateProvider.java:update 语句生成器,支持根据 ID、主键修改数据 BaseEntity.java:所有实体类的父类,提供了自定义查询条件、分页查询、排序的扩展 BaseException.java:自定义异常,在通用 Mapper 运行过程中抛出的异常 BaseMapper.java:所有 Mapper 的父类,提供了通用 Mapper 功能 SqlFieldReader.java:Sql 字段解析类,用于解析实体类中的自定义注解,为生成 Sql 语句服务 TypeCaster.java:类型转换,用于将 Java 中的数据类型转换成相应的 MySql 数据类型 util:工具类相关 Console.java:日志输出工具类,用于在控制台、日志文件中输出相关信息 ObjectUtils.java:Object 工具类,用于对象的空值判断 StringUtils.java:字符串工具类,用于生成指定格式的字符串及对字符串进行各种处理 使用方式 实体类继承 BaseEntity 并使用注解 @TableAttribute(name = "user_info",comment = "用户信息表") public class UserInfo extends BaseEntity { // 标注是自增主键 @KeyAttribute(autoIncr = true) // 标注是数据库字段 @FieldAttribute private int id; // 设置字段注释、非空约束、作为查询条件 @FieldAttribute(value = "用户类型",notNull = true,isCondition = true) private Integer type; @FieldAttribute(value = "密码",length = 200, isDetailed = true) private String password; // 设置字段注释、非空约束、字段长度、是索引字段 @FieldAttribute(value = "邮箱",notNull = true,length = 200,isIndex = true) private String email; @FieldAttribute @SortAttrtibute private Date createTime = new Date(); @FieldAttribute(value = "用户账号状态",isCondition = true) private Integer status ; @FieldAttribute(value = "是否删除,1 表示删除",isCondition = true) private Integer isDelete; ... ... } Dao 层继承 BaseMapper @Mapper public interface UserMapper extends BaseMapper { } 调用 /** * 根据类型和邮箱查询用户 * @param type * @param email * @return */ private UserInfo getByEmailAndType(int type,String email){ UserInfo userInfo = new UserInfo(); // 设置查询条件1 Email userInfo.setEmail(email); // 设置查询条件2 Type userInfo.setType(type); // 设置使用 And 连接多个查询条件 userInfo.setBaseKyleUseAnd(true); // 执行查询并返回结果 List list = userMapper.baseSelectList(userInfo); if(list != null && list.size() > 0){ return list.get(0); } return null; }

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧