今天在采集错误时,发现有一个诡异异常:
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()都要判断是否为空指针是多么可怕的事情啊!
分享到:
相关推荐
package andr.liu; import android.app.Activity;... System.out.println("123ww565"); System.out.println("www"); System.out.println("123565"); } OnClickListener operator1=new View.OnClickLis
System.out.println("Object is null: " + e.getMessage()); } ``` 3. **异常处理的最佳实践**:合理地使用异常处理可以提高程序的健壮性和可维护性。通常建议在可能抛出异常的地方捕获异常,并给出合适的错误...
System.out.println(line); } reader.close(); ``` 2. 使用`InputStream`和`BufferedReader`: ```java File file = new File("file_path"); InputStream is = new FileInputStream(file); BufferedReader ...
System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("City: " + city); ``` 2. 使用Gson库解析JSON: ```java import com.google.gson.Gson; import java.util.Map; /...
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("Tag capacity is " + ndef.getMaxSize() + " bytes, message is " + size + " bytes."); return false; } ndef.writeNdefMessage(message); System.out.println("****写入数据成功***"); ...
System.out.println(line); } br.close(); } catch (IOException e) { e.printStackTrace(); } } } ``` 这里,我们首先创建一个`File`对象,然后用`BufferedReader`读取文件内容。如果文件包含二进制数据,...
System.out.println(sb.toString()); System.out.println(""); } fos.close(); is.close(); } zipFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } } ``` #### 四、关键步骤分析...
System.out.println("Android 发行版本: " + releaseVersion); } } ``` 运行这段代码,就能在控制台看到设备的相关信息。 除了直接使用Android提供的API,还可以通过读取系统文件来获取更详细的硬件信息。例如,...
System.out.println(ex.getMessage()); } } ``` 方法三:Java调用控制台执行ping命令 这种方法是通过程序调用控制台执行ping命令,具体的思路是这样的:通过程序调用类似“ping 127.0.0.1 -n 10 -w 4”的命令,...
System.out.println("接收到的消息:" + str); // 发送消息 PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())), true); out.println("Server Message: ...
System.out.println("接收到的信息:" + str); // 向客户端发送信息 PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())), true); out.println("服务器...
System.out.println("无法获取串口输入/输出流"); e.printStackTrace(); return; } try { serialPort.addEventListener(this); serialPort.notifyOnDataAvailable(true); } catch (Exception e) { System....
// 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....
System.out.println("start..."); socket = server.accept(); System.out.println("accept..."); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); String message =...
System.out.println(pinyinArray[0]); } } } } ``` 在上述代码中,`PinyinHelper.toHanyuPinyinStringArray()`会返回一个字符串数组,包含该字符的所有可能拼音。对于单音节字,数组长度为1;对于多音字,数组...
System.out.println("Server started, listening on port " + port); while (true) { clientSocket = serverSocket.accept(); System.out.println("Accepted connection from client"); writer = new ...
Runnable r = () -> System.out.println("Hello, Lambda!"); ``` 其次,Stream API是Java 8中另一个显著改进。它提供了一种声明式处理数据的方式,适用于集合和其他数据源。通过流,我们可以方便地执行过滤、映射、...
System.out.println("onPageScrolled OnRearrangeListener.onRearrange from=" oldIndex ", to=" newIndex); String item = mAdapter.getItem(oldIndex); mAdapter.setNotifyOnChange(false)...
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 ?