我已经找到了所有的解决方案并应用到我的项目中。但它们不起作用。我被拒绝了这个许可。我已经把所有可能的许可都放进了清单文件。请告诉我我的项目出了什么问题。
public static void getGetResponse() {
InputStream inputStream = null;
try {
URL url = new URL("http://120.26.89.113:8080/common/qiniuToken");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
String userPassword = "wehelper:***********";
byte[] encodedBytes = Base64.encode(userPassword.getBytes(), 0);
connection.setRequestProperty("Authorization", "Basic " + encodedBytes);
connection.connect();
int resCode = connection.getResponseCode();
if (resCode == 200) {
inputStream = connection.getInputStream();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder out = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
out.append(line);
}
System.out.println(out.toString());//Prints the string content read from input stream
Log.d("myApp",out.toString());
reader.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
我的manifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MyMaterialTheme">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Logcat:
W/System.err: java.net.SocketException: socket failed: EACCES (Permission denied)
W/System.err: at libcore.io.IoBridge.socket(IoBridge.java:619)
W/System.err: at java.net.PlainSocketImpl.create(PlainSocketImpl.java:198)
W/System.err: at java.net.Socket.checkOpenAndCreate(Socket.java:689)
W/System.err: at java.net.Socket.setSoTimeout(Socket.java:543)
W/System.err: at com.android.okhttp.internal.http.SocketConnector.connectRawSocket(SocketConnector.java:433)
W/System.err: at com.android.okhttp.internal.http.SocketConnector.connectCleartext(SocketConnector.java:105)
W/System.err: at com.android.okhttp.Connection.connect(Connection.java:1331)
W/System.err: at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:1410)
W/System.err: at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:466)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:447)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:353)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:468)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:118)
W/System.err: at com.donghuaxue.spoonhunt.HttpClient.getGetResponse(HttpClient.java:44)
W/System.err: at com.donghuaxue.spoonhunt.MainActivity.onCreate(MainActivity.java:42)
W/System.err: at android.app.Activity.performCreate(Activity.java:6876)
W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
W/System.err: at android.app.ActivityThread.access$1100(ActivityThread.java:222)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:158)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7229)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
W/System.err: Caused by: android.system.ErrnoException: socket failed: EACCES (Permission denied)
W/System.err: at libcore.io.Posix.socket(Native Method)
W/System.err: at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282)
W/System.err: at libcore.io.IoBridge.socket(IoBridge.java:604)
W/System.err: ... 27 more
您的<代码>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MyMaterialTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我得到了一个Android应用程序,但当我启动它时,我得到了一个错误在我的控制台。我正在使用一个数据报套接字创建连接,并且使用了两个类:(这是应用程序的主要活动)和来创建连接。 这里的代码MainActivity: 但它不起作用。
我收到错误消息 这是我的清单文件: 如何修复此问题?
我找了几个地方,试了很多东西,但我不明白这里出了什么问题:(请帮帮我。
我该怎么修好它?或者请将我转到关于该主题的教程。
更新 结果发现我调用open和close FileOutputStream的频率太高了,这会在某个时候抛出FileNotFoundException。听起来更像是线程问题。