简单的东西,我在课堂上学习 URL/网络,我试图在网页上显示一些东西。稍后我要将它连接到 MySQL DB ......无论如何,这是我的程序:
import java.net.*; import java.io.*;
public class asp {
public static URLConnection
connection;
public static void main(String[] args) {
try {
System.out.println("Hello World!"); // Display the string.
try {
URLConnection connection = new URL("post.php?players").openConnection();
}catch(MalformedURLException rex) {}
InputStream response =
connection.getInputStream();
System.out.println(response);
}catch(IOException ex) {}
} }
它编译得很好......但是当我运行它时,我得到:
你好世界!
asp.main(asp.java:17) 处的线程“main”java.lang.NullPointerException 中的异常
第 17 行:InputStream 响应 = connection.getInputStream();
谢谢,丹