【【java】[null]的问题】教程文章相关的互联网学习教程文章

java – 外键更新异常:在Hibernate一对多关系中将外键设置为null【代码】

我发现当更新一对多关系中的父表时,子表上的依赖数据的外键被设置为null,在子表上留下孤立记录. 我有两个用Hibernate标签注释的Java类.父表是:@Entity @Table(name = "PERSON") public class Person implements Serializable {// Attributes. @Id @Column(name="PERSON_ID", unique=true, nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) private Integer personId;@Column(name="NAME", nullable=false,...

java – Servlet request.getParameter()总是返回“null”【代码】

我已经阅读了所有相关问题,尝试了每个接受的答案,但我仍然没有找到运气. 我有一个在tomcat上运行的网站,有一个子页面/ Demo /,它有四个文本字段和一个Submit按钮.提交按钮如下所示<form method="post" action="DemoServlet"><input type="hidden" name="form_action" value="write" /><table><tr><td>First Name:</td><td><input type="text" name="firstname" /></td></tr><tr><td>Last Name:</td><td><input type="text" name="l...

java – 无法在spock中的null对象上调用方法leftshift()【代码】

下面的代码是spock测试的一个非常基本的例子.当我运行它时,它会出现以下错误 无法在null对象上调用方法leftshift() 为什么,我如何使我的代码工作? 另外,leftshift和rightshift在spock中的用途究竟是什么.import spock.lang.*;class Publisher {List <Subscriber> subscribers void send (String message){} }interface Subscriber {void receive(String message) }public class Test1 extends Specification {Publisher p...

java – 使用Spring依赖注入时,Hibernate SessionFactory始终为null【代码】

我在CityDaoImpl中的save方法中得到NullpointerException.似乎sessionFactory没有自动装配,因为在调试时发现sessionFactory从未在CityDaoImpl中注入.我看了很多答案,但没有一个能解决我的问题.这是我的HibernateConfig.xml文件:<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www....

java.lang.IllegalArgumentException:在触发get请求时,主机名可能不为null【代码】

我将非常感谢您对此的帮助,下面是我正在尝试执行的代码,但所有我得到的是这个例外,我做了很多更改,但我无法解决这个问题. 如果你有任何指针,请告诉我,我在Android 4.4.4上运行HttpGet request = new HttpGet("https://s3--eu--west--1.amazonaws.com/developer-application--test/cart/list"); resp = client.execute(request);01-22 22:25:03.885: W/System.err(14697): java.lang.IllegalArgumentException: Host name may not b...

java – EnumMap.containsValue(null)返回true J​​DK 7【代码】

我发现了一种奇怪的行为.我使用的是JDK 1.7.当我打印map.containsValue(null) 虽然我的MAP中没有任何空值,但它返回true.import java.util.EnumMap; import java.util.Map;public class EnumMapTest {enum EnumType {ZERO, ONE, TWO}public static void main(String[] args) {Map<EnumType, Integer> map = new EnumMap<EnumType, Integer>(EnumType.class);map.put(EnumType.ZERO, 0);System.out.println(map.containsValue(null))...

java – jersey2单元测试,HttpServletRequest为null【代码】

请大家帮忙? 泽西Bug连接:[1]:https://java.net/jira/browse/JERSEY-2412 当我使用测试提供程序(测试的jetty和grizzly2)时,servlet请求,响应和上下文没有注入到类中.我使用包注释来提取应用程序. 你有其他方法吗?public class VMResourceTest extends BaseTest { @Test public void testCreateVm() { String bodyData = loadClassPathData(CLASS_PATH+File.separator+"tools"+File.separator+"createVm.json"); Response r...

为什么即使在loadContent(…)之后Document也为null? – (WebView JavaFx)【代码】

这是MainController类初始化(…)方法的简单代码:WebEngine webEngine = webView.getEngine(); webEngine.loadContent("<h1>hello</h1>"); // Successfully loaded on form Document doc = webEngine.getDocument(); // null 为什么doc是null以及如何修复它?解决方法:正如我评论的那样,一旦内容成功加载,你应该添加一个监听器,因为加载需要时间,以便执行:final WebView webView = new WebView(); final WebEngine webEngine = we...

添加时,java arraylist null指针异常【代码】

有人可以帮我理解为什么我在添加到我的数组列表时会得到一个空指针.我试图使它在单击按钮时更改按钮上的文本,但是我的ArrayList似乎没有将内容添加到其中?public class Game {private GUI gui; private ArrayList<String> pairs; boolean clicked; public Game() {gui = new GUI(this);clicked = false; ArrayList<String> pairs = new ArrayList<String>();}public void addPairs() {pairs.add("dog"); // where i get the null ...

java – getAnnotation为多个注释返回null【代码】

我有一个可重复的注释@Repeatable(Examples.class) public @interface Example {int value(); }使用容器注释@Retention(RetentionPolicy.RUNTIME) public @interface Examples {Example[] value(); }然后我尝试启动此代码@Example(1) @Example(2) public class Test {public static void main(String[] args) {Example example = Test.class.getAnnotation(Example.class);System.err.println(example);} }但是它打印为null.怎么可...

java – spring jpa auditing lastmodifiedby和lastmodifiedDate都可以,但createdBy和createdDate注释总是为null【代码】

我正在尝试设置(作为一个java初学者)spring jpa审计现在几小时/几天…而且我开始变得非常沮丧,因为我找不到问题.我真的很感激一些帮助. @ LastModifiedBy和@LastModifiedDate注释正在工作,但@CreatedBy和@CreatedDate始终为NULL. 这是sql查询调试输出:2017-06-16 16:40:39 [main] DEBUG n.t.d.l.l.SLF4JQueryLoggingListener n.t.d.s.SLF4JLogUtils writeLog – 名称:,时间:0,成功:False,类型:Prepared,Batch:False,QuerySi...

java – 使用Optional.orElseGet()返回null并设置响应值【代码】

我有一个TeamResponse类用于形成JSON响应.它有一些参数,其中一个可以是可选的:public TeamResponse(Team team, List<TeamSkillTemplateResponse> teamSkillTemplateResponses) {this.id = team.getId();this.name = team.getName();this.department = new DepartmentResponse(team.getDepartment());this.division = new DivisionResponse(team.getDepartment().getDivision());this.valueStream = team.getValueStream().map(Val...

Java Google Cloud Storage上传媒体链接为null,但图片上传【代码】

我正在尝试将图片上传到Google云端存储中的现有存储分区.我去检查时图像文件上传成功,但返回的下载网址为空 码private String uploadImage(File filePath, String blobName, File uploadCreds) throws FileNotFoundException, IOException{Storage storage = StorageOptions.newBuilder().setProjectId("myProjectId").setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream(uploadCreds))).build().getServic...

java – 将字符串比较为null或空时返回boolean【代码】

我正在尝试将以下代码迁移到java 8private boolean test(String id1, String id2) {if(id2== null || id2.isEmpty()) return true;return id1.equals(id2);}解决了尝试Optional.ofNullable(id2).map(String::isEmpty).orElse(id2.equals(id1));以上解决方案无效id2 is null id2 is equal to id1解决方法:可选项并不意味着取代简单的if检查.您实质上是“迁移”到一个不太可读和有效的解决方案. 如果我是你,我会坚持使用你当前的解决...

java – 检查null时的惯用Kotlin【代码】

在Java中,我会做这样的事情:class Person {private Record record;public String name() {record().get("name");}private Record record() {if (record == null) {refetch();}return record;}private void refetch() {record = service.doSomething()}}在Kotlin,我有这个等价的代码:class Person(private var record: Record?) {fun name() : String {record().get("name");}private fun record() : Record {record ?: refetch()...

NULL - 相关标签