【Java直接修改类,null引用?】教程文章相关的互联网学习教程文章

java – 当某些字节错误时,BitmapFactory.decodeStream(inputStream)总是返回null【代码】

我正在构建一个Android应用程序,我目前无法从URL中检索位图.这是我正在使用的代码:public static Bitmap bmpFromURL(URL imageURL){Bitmap result = null;try {HttpURLConnection connection = (HttpURLConnection)imageURL .openConnection();connection.setDoInput(true);connection.connect();InputStream input = connection.getInputStream();result = BitmapFactory.decodeStream(input);} catch (IOException e) {e.printS...

java – Hibernate:org.hibernate.AssertionFailure:com.xxx.Bean条目中的null id【代码】

我遇到了以下错误:com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract void com.xxx.Service.save(com.xxx.Bean)' threw an unexpected exception: org.hibernate.AssertionFailure: null id in com.xxx.Bean entry (don't flush the Session after an exception occurs)at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:385)at com.google.gwt.user.server.rpc.RPC...

在Java中尝试从另一个类访问变量时获取null【代码】

我有两个类,我想将一个(地理点)变量从一个传递到另一个,这样我就可以计算用户当前位置和地理点之间的距离. 长话短说: 我的第一个类名为Session,第二个名为 – 它们位于同一个包中. 我在主类中声明变量为public.在触摸时,我将用户当前位置保存到名为userposition的(公共)地理点变量中. 然后在我使用的第二课Session pass = new Session();创建Session的实例.之后我尝试检索用户位置变量:Geopoint position = pass.userposition;但...

java – 为什么cast(Object)null结果为null?【代码】

我使用java 7,并创建了一个varargs方法public class JavaApplicationTest {/*** @param args the command line arguments*/public static void main(String[] args) {addBundleMessage("b", Integer.SIZE, "key", (Object) null);}public static void addBundleMessage(String bundleName, Integer severity, String key, Object... params) {if (params == null)System.out.println("params Is null");elseSystem.out.println("Pa...

java.io.ioexception.Runtime.getRuntime().EXEC(). android中的环境和工作目录null错误【代码】

File dir = new File("/mnt/sdcard"); Process process = Runtime.getRuntime().exec("ffmpeg -f image2 -i img%4d.png video.mp4", null, dir);当我在android中尝试这一行时,我在android中得到环境和工作目录null错误.但是当我在java中尝试该行时,它工作得很好.但在android中,它有一些问题.解决方法: i get environment and working directory null它将返回null,因为没有像/ mmt / sdcard这样的路径而是使用/ mnt / sdcard. 最好使...

java – 如何在泛型中实现null对象模式?【代码】

我喜欢null object pattern的想法并强迫我使用它直到它真的感觉正常和好.目前我没有看到如何在泛型类型中使用它.我知道定义第二个泛型类型并传入类来构造一个默认对象的可能性,但这对于这个模式来说真的太多了.有好办法吗?public class GenericExample<T> {public static final GenericExample NULL = ???;private T attribute;public GenericExample(T attribute) {this.attribute = attribute;} }public class HoldGeneric {pri...

什么时候在java中使用null?【代码】

假设我有一个Node类型.public class Node{private Node next;private int data;// other methods including constructor and setting next reference. }或者使用null作为未初始化的值,如下所示:public class Node{private Node next = null;private int data; }解决方法: public class Node{private Node next; //initialized to nullprivate int data; //initialized to 0// other methods including constructor and setting n...

java – getApplicationContext()返回null,但适用于其他活动【代码】

我正在使用SQLite数据库,每当我调用它时,我都需要将上下文传递给它.我通常使用getApplicationContext()来执行此操作,该工作在其他活动中.在我当前的类中,它只返回null.救命!04-06 16:46:19.523: E/AndroidRuntime(4279): Process: com.example.schoolandrevisiontimetable, PID: 4279 04-06 16:46:19.523: E/AndroidRuntime(4279): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.school...

Java- Getters返回Null【代码】

我正在为类进行一个抽象的超类练习,我仍然坚持为什么我的getter返回null.根据我的教师演示的方式,在子类中重写了setter,并且getter将成为超类中的最终方法.当我将它们移动到子类时,getter工作,所以我猜它与它们在不同的类中的事实有关,但由于我是面向对象编程的新手,我不知道这是不是为什么和/或如何纠正这个问题. 摘要超类:public abstract class ProgrammingCourse {private double credits;private String courseName;public ...

java – 确保所有集合元素都为非null的现有实用程序方法【代码】

Java 8标准库或Guava中是否存在现有的实用程序方法,以确保集合不为null并且每个元素(如果有)都不为null? 就像Objects.requireNonNull()的“集合版本”. 到目前为止我找不到这样的东西.现在我写了一个简单的实用函数来完成这项工作:public static void requireAllNonNull(final Collection<?> collection) {Objects.requireNonNull(collection, "Collection must not be null");if (collection.stream().anyMatch(Objects::isNull...

java – Spring Security getAuthentication()返回null【代码】

我正在尝试从Spring Boot AngularJS应用程序返回当前登录的用户,但SecurityContextHolder.getContext().getAuthentication()返回null. 安全配置:@Configuration @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter {@Autowiredpublic void configureGlobal(AuthenticationManagerBuilder auth) throws Exc...

使用.equals()返回时,Java跳过null对象【代码】

我正在尝试一些代码优化,我对一个对象的当前唯一标题验证如下所示:public boolean validateTitle(RawProfileConstraint rawProfileConstraint) {RawProfileConstraint result = profileConstraintMapper.validateTitle(rawProfileConstraint.getTitle());return (!rawProfileConstraint.getTitle().equals(result.getTitle())); }这是有效的,直到它发出爆炸声,数据库无法检索包含我正在尝试验证的标题的记录 – a.k.a它可用.在这...

java.io.IOException: (null) entry in command string: null chmod 0644报错【图】

Java代码实现Hadoop客服端下载文件时报错解决办法第一个false表示不会删除源文件 第二个true表示使用本地文件系统

Design Pattern----22.Behavioral.Null Object.Pattern (Java Sample)【代码】【图】

原文链接:http://www.cnblogs.com/xiuyusoft/archive/2011/07/01/2095430.htmlIntent The intent of a Null Object is to encapsulate the absence of an object by providing a substitutable alternative that offers suitable default do nothing behavior. In short, a design where “nothing will come of nothing” Use the Null Object pattern when an object requires a collaborator. The Null Object pattern do...

如何在任何Java地图实现上测试null键?【代码】

我想确保作为参数传递给方法的Map不包含null键.人们会认为以下情况会:if ( map.containsKey(null) ) …但是如果传递的方法类似于TreeMap,那将会破坏,根据一般的Java Map合约是free to reject null keys with a NPE. 我们是否有一种合理的方法来测试null键,同时接受任何Map实现?解决方法: boolean hasAnyNull = yourMap.keySet().stream().anyMatch(Objects::isNull);