- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用这个java wrapper用于 Reddit API。基本上,我正在开发一个 android reddit 应用程序。这是我的 MainActivity.java
代码:
package com.example.reddit;
import im.goel.jreddit.submissions.Submission;
import im.goel.jreddit.submissions.Submissions;
import im.goel.jreddit.user.User;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView username;
private TextView password;
private User reddit;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String usern = username.getText().toString();
String passw = password.getText().toString();
reddit = new User(usern, passw);
try {
reddit.connect();
List<Submission> submissions = Submissions.getSubmissions(
"cfb",
Submissions.Popularity.HOT,
Submissions.Page.FRONTPAGE,
reddit);
for(Submission submission: submissions) {
System.out.println(submission);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我在 Debug模式下运行它,当它执行行 reddit.connect();
时,它会抛出异常。 logcat 的内容如下:
12-01 14:54:03.670: W/ActivityThread(6095): Application com.example.reddit is waiting for the debugger on port 8100...
12-01 14:54:03.670: I/System.out(6095): Sending WAIT chunk
12-01 14:54:03.690: I/dalvikvm(6095): Debugger is active
12-01 14:54:03.870: I/System.out(6095): Debugger has connected
12-01 14:54:03.880: I/System.out(6095): waiting for debugger to settle...
12-01 14:54:04.080: I/System.out(6095): waiting for debugger to settle...
12-01 14:54:04.280: I/System.out(6095): waiting for debugger to settle...
12-01 14:54:04.480: I/System.out(6095): waiting for debugger to settle...
12-01 14:54:04.680: I/System.out(6095): waiting for debugger to settle...
12-01 14:54:04.880: I/System.out(6095): waiting for debugger to settle...
12-01 14:54:05.080: I/System.out(6095): waiting for debugger to settle...
12-01 14:54:05.290: I/System.out(6095): debugger has settled (1380)
12-01 14:54:05.630: D/PhoneWindow(6095): DebugMonitor class=com.example.reddit.MainActivity focus=true
12-01 14:54:40.570: W/System.err(6095): java.net.SocketException: Permission denied (maybe missing INTERNET permission)
12-01 14:54:40.590: W/System.err(6095): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
12-01 14:54:40.590: W/System.err(6095): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:187)
12-01 14:54:40.600: W/System.err(6095): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:266)
12-01 14:54:40.600: W/System.err(6095): at java.net.Socket.checkClosedAndCreate(Socket.java:872)
12-01 14:54:40.610: W/System.err(6095): at java.net.Socket.connect(Socket.java:1019)
12-01 14:54:40.610: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
12-01 14:54:40.620: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
12-01 14:54:40.620: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
12-01 14:54:40.630: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:821)
12-01 14:54:40.630: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:807)
12-01 14:54:40.630: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:395)
12-01 14:54:40.630: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.sendRequest(HttpURLConnection.java:1224)
12-01 14:54:40.630: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequestInternal(HttpURLConnection.java:1563)
12-01 14:54:40.630: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequest(HttpURLConnection.java:1556)
12-01 14:54:40.630: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1145)
12-01 14:54:40.640: W/System.err(6095): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.getOutputStream(HttpsURLConnection.java:262)
12-01 14:54:40.640: W/System.err(6095): at im.goel.jreddit.utils.Utils.post(Utils.java:49)
12-01 14:54:40.640: W/System.err(6095): at im.goel.jreddit.user.User.hashCookiePair(User.java:266)
12-01 14:54:40.640: W/System.err(6095): at im.goel.jreddit.user.User.connect(User.java:45)
12-01 14:54:40.640: W/System.err(6095): at com.example.reddit.MainActivity$1.onClick(MainActivity.java:39)
12-01 14:54:40.640: W/System.err(6095): at android.view.View.performClick(View.java:2364)
12-01 14:54:40.640: W/System.err(6095): at android.view.View.onTouchEvent(View.java:4179)
12-01 14:54:40.640: W/System.err(6095): at android.widget.TextView.onTouchEvent(TextView.java:6661)
12-01 14:54:40.640: W/System.err(6095): at android.view.View.dispatchTouchEvent(View.java:3709)
12-01 14:54:40.640: W/System.err(6095): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
12-01 14:54:40.650: W/System.err(6095): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
12-01 14:54:40.650: W/System.err(6095): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
12-01 14:54:40.650: W/System.err(6095): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
12-01 14:54:40.650: W/System.err(6095): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695)
12-01 14:54:40.650: W/System.err(6095): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
12-01 14:54:40.650: W/System.err(6095): at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
12-01 14:54:40.650: W/System.err(6095): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679)
12-01 14:54:40.650: W/System.err(6095): at android.view.ViewRoot.handleMessage(ViewRoot.java:1708)
12-01 14:54:40.650: W/System.err(6095): at android.os.Handler.dispatchMessage(Handler.java:99)
12-01 14:54:40.650: W/System.err(6095): at android.os.Looper.loop(Looper.java:123)
12-01 14:54:40.660: W/System.err(6095): at android.app.ActivityThread.main(ActivityThread.java:4595)
12-01 14:54:40.660: W/System.err(6095): at java.lang.reflect.Method.invokeNative(Native Method)
12-01 14:54:40.660: W/System.err(6095): at java.lang.reflect.Method.invoke(Method.java:521)
12-01 14:54:40.660: W/System.err(6095): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-01 14:54:40.660: W/System.err(6095): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-01 14:54:40.660: W/System.err(6095): at dalvik.system.NativeStart.main(Native Method)
12-01 14:55:37.200: W/ActivityThread(6128): Application com.example.reddit is waiting for the debugger on port 8100...
12-01 14:55:37.210: I/System.out(6128): Sending WAIT chunk
12-01 14:55:37.210: I/dalvikvm(6128): Debugger is active
12-01 14:55:37.410: I/System.out(6128): Debugger has connected
12-01 14:55:37.410: I/System.out(6128): waiting for debugger to settle...
12-01 14:55:37.610: I/System.out(6128): waiting for debugger to settle...
12-01 14:55:37.810: I/System.out(6128): waiting for debugger to settle...
12-01 14:55:38.010: I/System.out(6128): waiting for debugger to settle...
12-01 14:55:38.210: I/System.out(6128): waiting for debugger to settle...
12-01 14:55:38.410: I/System.out(6128): waiting for debugger to settle...
12-01 14:55:38.610: I/System.out(6128): waiting for debugger to settle...
12-01 14:55:38.820: I/System.out(6128): debugger has settled (1437)
12-01 14:55:39.150: D/PhoneWindow(6128): DebugMonitor class=com.example.reddit.MainActivity focus=true
12-01 14:55:56.620: W/System.err(6128): java.net.SocketException: Permission denied (maybe missing INTERNET permission)
12-01 14:55:56.630: W/System.err(6128): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
12-01 14:55:56.630: W/System.err(6128): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:187)
12-01 14:55:56.630: W/System.err(6128): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:266)
12-01 14:55:56.630: W/System.err(6128): at java.net.Socket.checkClosedAndCreate(Socket.java:872)
12-01 14:55:56.630: W/System.err(6128): at java.net.Socket.connect(Socket.java:1019)
12-01 14:55:56.630: W/System.err(6128): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
12-01 14:55:56.630: W/System.err(6128): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
12-01 14:55:56.630: W/System.err(6128): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
12-01 14:55:56.640: W/System.err(6128): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:821)
12-01 14:55:56.640: W/System.err(6128): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:807)
12-01 14:55:56.640: W/System.err(6128): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getResponseCode(HttpURLConnection.java:1272)
12-01 14:55:56.640: W/System.err(6128): at im.goel.jreddit.utils.Utils.get(Utils.java:99)
12-01 14:55:56.640: W/System.err(6128): at im.goel.jreddit.submissions.Submissions.getSubmissions(Submissions.java:62)
12-01 14:55:56.640: W/System.err(6128): at com.example.reddit.MainActivity$1.onClick(MainActivity.java:41)
12-01 14:55:56.640: W/System.err(6128): at android.view.View.performClick(View.java:2364)
12-01 14:55:56.640: W/System.err(6128): at android.view.View.onTouchEvent(View.java:4179)
12-01 14:55:56.640: W/System.err(6128): at android.widget.TextView.onTouchEvent(TextView.java:6661)
12-01 14:55:56.640: W/System.err(6128): at android.view.View.dispatchTouchEvent(View.java:3709)
12-01 14:55:56.650: W/System.err(6128): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
12-01 14:55:56.650: W/System.err(6128): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
12-01 14:55:56.650: W/System.err(6128): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
12-01 14:55:56.650: W/System.err(6128): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
12-01 14:55:56.650: W/System.err(6128): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695)
12-01 14:55:56.650: W/System.err(6128): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
12-01 14:55:56.650: W/System.err(6128): at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
12-01 14:55:56.650: W/System.err(6128): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679)
12-01 14:55:56.650: W/System.err(6128): at android.view.ViewRoot.handleMessage(ViewRoot.java:1708)
12-01 14:55:56.660: W/System.err(6128): at android.os.Handler.dispatchMessage(Handler.java:99)
12-01 14:55:56.660: W/System.err(6128): at android.os.Looper.loop(Looper.java:123)
12-01 14:55:56.660: W/System.err(6128): at android.app.ActivityThread.main(ActivityThread.java:4595)
12-01 14:55:56.660: W/System.err(6128): at java.lang.reflect.Method.invokeNative(Native Method)
12-01 14:55:56.660: W/System.err(6128): at java.lang.reflect.Method.invoke(Method.java:521)
12-01 14:55:56.660: W/System.err(6128): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-01 14:55:56.660: W/System.err(6128): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-01 14:55:56.660: W/System.err(6128): at dalvik.system.NativeStart.main(Native Method)
12-01 14:58:00.410: W/ActivityThread(6166): Application com.example.reddit is waiting for the debugger on port 8100...
12-01 14:58:00.410: I/System.out(6166): Sending WAIT chunk
12-01 14:58:00.420: I/dalvikvm(6166): Debugger is active
12-01 14:58:00.620: I/System.out(6166): Debugger has connected
12-01 14:58:00.620: I/System.out(6166): waiting for debugger to settle...
12-01 14:58:00.820: I/System.out(6166): waiting for debugger to settle...
12-01 14:58:01.020: I/System.out(6166): waiting for debugger to settle...
12-01 14:58:01.220: I/System.out(6166): waiting for debugger to settle...
12-01 14:58:01.420: I/System.out(6166): waiting for debugger to settle...
12-01 14:58:01.620: I/System.out(6166): waiting for debugger to settle...
12-01 14:58:01.820: I/System.out(6166): waiting for debugger to settle...
12-01 14:58:02.030: I/System.out(6166): debugger has settled (1434)
12-01 14:58:02.380: D/PhoneWindow(6166): DebugMonitor class=com.example.reddit.MainActivity focus=true
这是什么java.net.SocketException
以及如何修复它?
最佳答案
因此,从日志java.net.SocketException:权限被拒绝(可能缺少 INTERNET 权限)
来看。我通过谷歌搜索发现了
添加INTERNET对 list 文件的权限。
您必须添加此行:
<uses-permission android:name="android.permission.INTERNET" />
在 AndroidManifest.xml
中的应用程序标记之外。感谢StackOverflow .
关于java - jReddit Java 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20317279/
非常感谢!我开始工作了, 我发现的唯一问题是,当获取特定的评论 ID 时 提交后会返回分解的评论, 例如 Reddit reddit = new Reddit("USER","PASSWORD");
我正在使用这个java wrapper用于 Reddit API。基本上,我正在开发一个 android reddit 应用程序。这是我的 MainActivity.java 代码: package
尝试运行使用jReddit library的应用程序时,抛出 No Such Field 错误: java.lang.NoSuchFieldError: org.apache.http.message
尝试导入 Jreddit 运行所需的 jar 文件时出现错误。 jreddit 的 github 页面上写着...... Dependencies JSON-simple Apache HttpCom
我想在Android Studio(v.1.1.0)中编写应用程序来浏览reddit。我找到了 API 包装器 jReddit 并想使用它。 起初我只是尝试初始化 RestClient (当我单击按钮
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我是一名优秀的程序员,十分优秀!