`
wjjxf
  • 浏览: 237517 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android无法System.out.println出null

阅读更多
今天在采集错误时,发现有一个诡异异常:
com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:298)
抛出空指针异常,NullPointerException,奇怪了,我没有调用这个方法啊,只是
System.out.println()出字符串信息?难不成println空指针字符串会出错为了验证这个问题,我特地写了如下代码再onCreate()里:
String responseBody = null;
System.out.println(responseBody);


当启动的时候你发现什么了,果然是应用程序异常退出,然后看到logcat里报空指针错误,天啊!怎么会这样。看了一下源码,
294    @Override
295    public synchronized void println(String s) {
296        if (builder.length() == 0) {
297            // Optimization for a simple println.
298            int length = s.length();
299
300            int start = 0;
....

天啊,这段代码竟然没有判断s是否为空指针而直接取length了,难怪会报异常,希望android源码开发者们能看到这个问题,并且改正,要不然每一次在System.out.println()都要判断是否为空指针是多么可怕的事情啊!
0
0
分享到:
评论
2 楼 wjjxf 2012-08-14  
xubingok 写道
System.out.println是JDK中的io流中的方法,和android源码有什么关系...
而且你觉得应该改成什么样呢,值为null的对象进行打印当然要报空指针错误.难道要打印一个null啊?打印时调用的都是toString方法,难道对象为null时,toString要输出"null"?

jdk里打印的是null
1 楼 xubingok 2012-07-23  
System.out.println是JDK中的io流中的方法,和android源码有什么关系...
而且你觉得应该改成什么样呢,值为null的对象进行打印当然要报空指针错误.难道要打印一个null啊?打印时调用的都是toString方法,难道对象为null时,toString要输出"null"?

相关推荐

    简单计算器

    package andr.liu; import android.app.Activity;... System.out.println("123ww565"); System.out.println("www"); System.out.println("123565"); } OnClickListener operator1=new View.OnClickLis

    android连接SQLite数据库源代码

    System.out.println("create a DataBase"); // execSQL函数用于执行sql语句 db.execSQL("create table person(personid integer primary key autoincrement, name varchar(20),age integer,tel varchar(20))"); ...

    目录选择器源代码

    // System.out.println("OnItemClick path1:"+path); if (temp.equals("..")) path = getSubDir(path); else if (path.equals("/")) path = path + temp; else path = path + "/" + temp; // System.out....

    Android-DraggableGridViewPager-仿zaker效果的拖拽排序.zip

    System.out.println("onPageScrolled OnRearrangeListener.onRearrange from=" oldIndex ", to=" newIndex); String item = mAdapter.getItem(oldIndex); mAdapter.setNotifyOnChange(false)...

    Android代码-heapunit

    HeapUnit Test library to introspecting your Java heap via heap dumps. HeapUnit can capture heap dump of own JVM scan content of dump reconstruct Java ... System.out.println(i.rehydrate() (open ?

    自定义相机

    System.out.println("正在进入切换摄像头模块"); //切换前后摄像头 int cameraCount = 0; Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraCount = Camera.getNumberOfCameras();//...

    自定义dialog

    ... import android.app.Dialog; import android.content.Context; import android.graphics.drawable.AnimationDrawable;... System.out.println("localStringBuilder=="+localStringBuilder); } } }

    全选?反选

    System.out.println(str.size()); } lv = (ListView) this.findViewById(R.id.lv); adapter=new MyAdapter(); lv.setAdapter(adapter); b_all = (Button) this.findViewById(R.id.b_all);//布局对应...

    图片缓存机制代码

    System.out.println("screenWidth:"+screenWidth+"=="+screenHeight); Options options = new Options(); //加载边框 一定options.inJustDecodeBounds = true; options.inJustDecodeBounds = true; Bitmap...

    Android通过距离传感器控制屏幕熄灭案例代码

    System.out.println("hands moved"); Log.d(TAG, "hands moved in calling activity"); if (localWakeLock.isHeld()) { return; } else { localWakeLock.setReferenceCounted(false); localWakeLock.release...

    android访问网络get post 源代码项目

    04 System.out.println(userName+"-"+password); 05 DataOutputStream dos = new DataOutputStream(response.getOutputStream()); 06 if (userName != null && password != null) { 07 if (userName.length() ...

    Android 连网下载APK文件并自动安装.rar

     System.out.println("myURL=" myURL);  URLConnection conn = myURL.openConnection(); //建立联机  conn.connect();  InputStream is = conn.getInputStream(); //InputStream 下载文件  if (is == null) /...

    android天气预告

    // System.out.println(t4); return t4; } catch (BadHanyuPinyinOutputFormatCombination e1) { e1.printStackTrace(); } return t4; } public Runnable updata = new Runnable() { public void run()...

    android手机通讯录备份还原代码

    System.out.println(phoneNumber); }while(phones.moveToNext()); } } str+="\r\n"; } while (cur.moveToNext()); } } 4.读文件代码 try { File file = new File("/sdcard/test.txt"); ...

    android 五子棋源码

    System.out.println("currentItem: " + currentItem); currentItem = (currentItem + 1) % imageViews.size(); handler.obtainMessage().sendToTarget(); } } } /*** * 当viewPager...

    android 上传文件

    System.out.println(response); String[] items = response.split(";"); String id = items[0].substring(items[0].indexOf("=")+1);//服务返回绑定该文件的资源id String position = items[1]....

    Android 日期控件只显示年月

    System.out.println("SDKVersion = " + SDKVersion); DatePicker dp = findDatePicker((ViewGroup) mdialog.getWindow() .getDecorView());// 设置弹出年月日 if (dp != null) { if (SDKVersion ) { ...

    from-java-to-kotlin:从Java到Kotlin-Java到Kotlin的备忘单

    从Java到Kotlin 从Java到Kotlin-Java到Kotlin的备忘单 打印到控制台 Java System . out . print( " Amit Shekhar " ... System . out . println( " Amit Shekhar " );...println ( " Amit Shekhar " ) ...otherName = null ;

    从Java到Kotlin:从Java到Kotlin-Java到Kotlin的备忘单

    System . out . print( " Amit Shekhar " ); System . out . println( " Amit Shekhar " ); Kotlin print ( " Amit Shekhar " ) println ( " Amit Shekhar " ) 常量和变量 Java String name = " Amit Shekhar " ; ...

    android折线图

    170 System.out.println("-yes-"+i); 171 mSelectedPoint = mPoints[i]; 172 } 173 } 174 break; 175 case MotionEvent.ACTION_MOVE: 176 if ( null != mSelectedPoint) 177 { 178 // ...

Global site tag (gtag.js) - Google Analytics