Tag: nullpointerexception

导出的JAR无法读取图像

我试图让图像显示在JPanel中。 这是我正在使用的代码: URL imageURL; BufferedImage image = null; ImageIcon icon; imageURL = getClass().getClassLoader().getResource(“images/audiorpglogo.png”); if (imageURL == null) { System.out.println(imageURL == null); try { imageURL = new File(“images/audiorpglogo.png”).toURI().toURL(); } catch (Exception e1) { imageURL = null; } } System.out.println(imageURL == null); try { image = ImageIO.read(imageURL); } catch (Exception e) { } System.out.println(image == null); icon […]

尝试插入SQLite时的NullPointerException – Android

任何关注Android标签的人都可能对我很熟悉。 我正在努力为我的高分榜实现SQLite数据库。 这也是我第一次使用SQLite。 我试图只插入两个变量 – int和long。 我的insert()方法无法正常工作。 除了上面讨论的内容之外的任何建议也表示赞赏。 预先感谢您的帮助。 Highscores.java public class Highscores extends Activity { DatabaseHelper dh; SQLiteDatabase db; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.highscoresmain); dh = new DatabaseHelper(this); dh.openDB(db); long x = 11; int y = 22; TextView rank = (TextView)findViewById(R.id.rank); TextView percentage = (TextView)findViewById(R.id.percentage); TextView score = (TextView)findViewById(R.id.score); TextView r1r […]

如何避免这种NullPointerException

我正在开发一款小型街机video游戏,我期待双重缓冲来改善动画效果。 我有一个类应该绘制空白图像,另一个类应该绘制一个简单的线。 但是,我一直在应该绘制线的行上得到NullPointerException class Render extends JPanel { public int dbWidth = 500, dbHeight = 400; public Image dbImage = null; public Graphics dbg; public void gameRender() { if( dbImage == null ) dbImage = createImage( dbWidth, dbHeight ); dbg = dbImage.getGraphics(); dbg.setColor( Color.white ); dbg.fillRect( 0, 0, dbWidth, dbHeight ); } } class MC […]

Java – 获取JSONObject时的NullPointerException

我正在尝试使用Lukencode的RestClient类在我的Android应用程序中实现登录function。 我有一个名为UserFunctions的类来通过RestClient检索JSONObject: public class UserFunctions { private RestClient restClient; private String json; private Context mContext; private static String login_tag = “login”; private static String register_tag = “register”; // constructor public UserFunctions(Context context){ restClient = new RestClient(“http://10.0.2.2:81/HGourmet/user”); mContext = context; } /** * function make Login Request * @param email * @param password * */ public […]

数组空指针exception错误

我继续我的学校项目,似乎遇到了另一个错误。 所以发生的事情基本上是我收到一个空指针exception,即使代码看起来很好。 我相信我的arrays出了问题,即使经过几个小时的搜索,我也无法找到错误。 再一次,任何帮助/解决方案将不胜感激。 import java.util.*; public class library { private static students stu1 = new students(65435, “Bob”, “Ted”); private static students stu2 = new students(45546, “Guy”, “Sid”); private static students stu3 = new students(78688, “Tim”, “Cas”); private static students stu4 = new students(45387, “Guy”, “Jim”); private static students stu5 = new students(12367, “Dom”, “Lam”); […]

java.lang.NullPointerException:尝试在空对象引用上调用虚方法’boolean java.lang.String.equals(java.lang.Object)’

我在运行我的项目时遇到错误。 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.olympic/com.prima.olympic.ProductDetail}: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object reference 这是完整的日志: 06-06 23:12:45.561: E/AndroidRuntime(17135): FATAL EXCEPTION: main 06-06 23:12:45.561: E/AndroidRuntime(17135): Process: com.example.olympic, PID: 17135 06-06 23:12:45.561: E/AndroidRuntime(17135): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.olympic/com.prima.olympic.ProductDetail}: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object […]

加载属性文件的Java NullPointerException

public class SupplierCalculatorApplet extends JApplet{ … public void init(){ loadProperties(); … } … private void loadProperties() { language = “en-us”;//getParameter(“Language”); prop = new Properties(); try { URL urlToProps = this.getClass().getResource(“config/” + language + “.properties”); prop.load(urlToProps.openStream());//Exception Caught Here } catch (IOException e) { } } 在上面指出的行中可以找到例外情况。 无论语言是否是有效的属性文件,我都会在同一行上捕获相同的exception。

使用数组时出现NullPointerException

我正在尝试为在线Java课程创建一个程序。 该程序包括Employee类和Name类。 我必须创建多个Employee对象并提示用户输入员工的姓名。 我将所有Employee对象存储在一个雇员数组中。 这是代码: //Creates employee array with the number of array elements being however many //employees there are: Employee employee[] = new Employee [ numEmp ]; for( int j = 0; j < numEmp; j++ ) { System.out.println( "Please enter the first name of employee number " + ( j + 1 ) […]

java三元条件奇怪的空指针exception

有人可以解释我为什么在第一种情况下检测到空指针,但另一方面没有? 也许他总是看第一种类型,但为什么只有在条件错误时才这样做。 @Test public void test1() { final Integer a = null; final Integer b = false ? 0 : a; //===> NULL POINTER EXCEPTION } @Test public void test2() { final Integer b = false ? 0 : null; //===>NOT NULL POINTER EXCEPTION } @Test public void test3() { final Integer a = null; […]

为什么返回null并分配给引用类型的三元条件表达式会导致NullPointerException?

我喜欢在java编程中使用三元条件表达式,但我遇到了一个问题: 以下代码是一个小例子,但它显示了我找到的问题。 public class Example { public Example() { Double x = 0.0; A a = new A(); x = a == null ? 0.0 : a.getY(); // Happens on this line System.out.println(x); } class A { Double y = null; private Double getY() { return y; } } public static void main(String[] args) { […]