虽然我在我的清单文件中添加了以下内容:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
我仍然收到以下错误:
07-09 13:26:18.650: E/Trace(10542): error opening trace file: No such file or directory (2)
07-09 13:26:19.830: D/dalvikvm(10542): GC_CONCURRENT freed 44K, 7% free 2774K/2960K, paused 17ms+5ms, total 111ms
07-09 13:26:19.910: W/System.err(10542): org.apache.http.conn.HttpHostConnectException: Connection to https://78.46.124.109 refused
07-09 13:26:19.919: W/System.err(10542): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
07-09 13:26:19.919: W/System.err(10542): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-09 13:26:19.919: W/System.err(10542): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-09 13:26:19.930: W/System.err(10542): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
07-09 13:26:19.930: W/System.err(10542): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-09 13:26:19.940: W/System.err(10542): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-09 13:26:19.940: W/System.err(10542): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
...
07-09 13:26:19.989: W/System.err(10542): Caused by: java.net.ConnectException: socket failed: EACCES (Permission denied)
07-09 13:26:20.020: W/System.err(10542): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:181)
07-09 13:26:20.020: W/System.err(10542): ... 22 more
07-09 13:26:20.020: W/System.err(10542): Caused by: java.net.SocketException: socket failed: EACCES (Permission denied)
07-09 13:26:20.040: W/System.err(10542): at libcore.io.IoBridge.socket(IoBridge.java:583)
07-09 13:26:20.040: W/System.err(10542): at java.net.PlainSocketImpl.create(PlainSocketImpl.java:201)
这是我在名为 Logic.java 的外部文件中的代码,该文件从 MainActivity.java 类中调用:
public class Logic {
public void getJSONFromUrl( String url )
{
URL myurl = null;
String jsoncode = "";
try {
myurl = new URL(url);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
URLConnection myconn =myurl.openConnection();
InputStream in= new BufferedInputStream(myconn.getInputStream());
InputStreamReader reader = new InputStreamReader(in);
BufferedReader br = new BufferedReader(reader);
String line;
StringBuilder sb = new StringBuilder();
while((line=br.readLine())!=null)
{
sb.append(line);
//Toast.makeText(getApplicationContext(), "i enter here",Toast.LENGTH_LONG).show();
}
jsoncode = sb.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("json from server:\n" + jsoncode );
}
}
我还能在这里做错什么?