我想捕获doInBackground中的线程异常并在onPostExcecute中打印错误消息.问题是我在onPostExecute中没有Throwable对象.如何捕获异常在非UI线程,并打印在UI线程的错误信息?
public class TestTask extends AsyncTask<Void, Void, List<String>> {
@Override
protected List<String> doInBackground(final Void... params) {
try {
...
return listOfString;
} catch(SomeCustomException e) {
...
return null;
}
}
@Override
protected void onPostExecute(final List<String> result) {
if(result == null) {
// print the error of the Throwable "e".
// The problem is I don't have the Throwable object here! So I can't check the type of exception.
}
}
}
Run Code Online (Sandbox Code Playgroud)
Arun回答后更新:
这是我的AsyncTask包装类.它打算在doInBackground中处理Exception,但我找不到一个好的解决方案来做到这一点.
public abstract class …Run Code Online (Sandbox Code Playgroud) 我有一个flyout有id"productFlyout".我试着设置它的背景颜色和宽度.它有红色但宽度不变.看来Metro不允许宽度太大.
JS档案:
productFlyout.winControl.show(dummyDOM, "bottom", "center");
Run Code Online (Sandbox Code Playgroud)
CSS文件:
#productFlyout {
background: red;
width: 1000px;
}
#productFlyout .win-flyout {
width: 1000px;
background: red;
}
Run Code Online (Sandbox Code Playgroud) 我想更改WebView字体."assets"文件夹中有2个文件.他们是:
assets/fonts/DejaVuSans.ttf和
资产/ CSS/result.css
我在StackOverflow上搜索了一些答案并找到了解决方案,但它不起作用.result.css使用@ font-face指令加载DejaVuSans.ttf.然后它被包含在传递给WebView :: loadDataWithBaseURL的数据的<link>标签中(代码如下).问题是CSS样式工作(文本是红色)但字体不是.当我显示语音符号时会出现方形字符(/'pə:sn /).
String resultText = "<html><head>";
resultText += "<link href=\"css/result.css\"" + " rel=\"stylesheet\" type=\"text/css\" />";
resultText += "<style>" + "@font-face { font-family: \"DejaVuSans\"; " + "" +
"src: url('file:///android_asset/fonts/DejaVuSans.ttf'); }</style>";
resultText += "</head>";
resultText += "<body><p>" + text + "</p>" + "</body></html>";
resultView.loadDataWithBaseURL("file:///android_asset/", resultText, "text/html", "utf-8", null);
Run Code Online (Sandbox Code Playgroud)
result.css:
@font-face {
font-family: "DejaVuSans";
/*src: url('fonts/DejaVuSans.ttf'); also not work*/
src: url('file:///android_asset/fonts/DejaVuSans.ttf');
}
body {
color: red;
}
Run Code Online (Sandbox Code Playgroud)
System.out.println(resultText)是:
<html><head><link href="css/result.css" rel="stylesheet" type="text/css" /><style>@font-face …Run Code Online (Sandbox Code Playgroud) session.openForRead(new Session.OpenRequest(activity).setCallback(statusCallback).setPermissions(Arrays.asList(permissions)));
Run Code Online (Sandbox Code Playgroud)
尝试将"publish_permission"传递给setPermission时,我收到此错误.为什么?怎么修?Facebook开发者在哪里?
com.facebook.FacebookException: Cannot pass a publish permission (publish_stream) to a request for read authorization
Run Code Online (Sandbox Code Playgroud) 我正在使用jwplayer在网站上显示视频。
我正在寻找一个可以从这些视频中提取缩略图的 jQuery 插件,因为上传者只上传视频,没有缩略图。我的目标是将视频显示为表格中的缩略图(如 Youtube)。
我有什么想法可以实现这一目标吗?
我正在编写Android远程应用程序.当我触摸并移动Android应用程序时,服务器计算机上的光标也会移动,但它会延迟大约一秒钟.
我的应用程序只是两个线程:客户端发送坐标,服务器接收它们,这就是全部.我的解决方案是通过ObjectInputStream传递dx,dy并使用Robot :: mouseMove移动光标.
你能给我一些防止光标延迟的建议吗?(顺利地像RemoteDroid ^^)
我的塞弗:
public void run() {
..........
while(true) {
// get dx, dy from ObjectInputStream
........
moveMouseByDelta(dx, dy);
}
...........
}
private void moveMouseByDelta(int dx, int dy)
{
try {
Point p = MouseInfo.getPointerInfo().getLocation();
int currentX = p.x;
int currentY = p.y;
Robot robot = new Robot();
robot.mouseMove(currentX + dx, currentY + dy);
} catch (AWTException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我的客户端(Android远程应用):
private void touchTouchPad(MotionEvent event)
{
int x = (int)event.getX(); …Run Code Online (Sandbox Code Playgroud) 我有这个DialogFragment.当我显示它时,它变为全屏,我的意思是它与当前屏幕重叠.如何使它像AlertDialog一样小?
我猜这是因为RelativeLayout因此我将LinearLayout包装在RelativeLayout之外,但没有任何改变.
public class LoginDialogFragment extends DialogFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme);
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.login_dialog, container, false);
final EditText emailEditText = (EditText)v.findViewById(R.id.emailEditText);
final EditText passwordEditText = (EditText)v.findViewById(R.id.passwordEditText);
final Button loginButton = (Button)v.findViewById(R.id.loginButton);
loginButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
checkLogin(emailEditText.getText().toString(), passwordEditText.getText().toString());
}
});
return v;
}
}
Run Code Online (Sandbox Code Playgroud)
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout …Run Code Online (Sandbox Code Playgroud) 我正在编写一个娱乐应用程序(一个用Android编写的RESTful应用程序)。我想向Facebook朋友展示并邀请他们加入我的应用程序。现在,我已成功加载FB朋友。接下来我该怎么办?请给我一个主意。
(我想我应该给他们发送邀请电子邮件。对吗?)
这是我的代码。它在数据不足时加载更多数据。我想在加载更多数据时向 GridView 添加页脚 ProgressBar。怎么做?我在 StackOverflow 上看到了很多问题,但没有答案。
public class MainActivity extends Activity {
private static final String TAG = "MainActivity";
private final List<Integer> commonImageList = new ArrayList<Integer>();
private int index = 0;
private boolean isLoading = false;
private static final int NUM = 18;
private ImageAdapter adapter;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Task task = new Task(mThumbIds, index);
task.setOnPostExecuteListener(new OnPostExecuteListener<List<Integer>>() {
@Override
public void onPostExecute(final List<Integer> result) {
System.out.println("RESULT: " + result);
if(result.isEmpty()) { …Run Code Online (Sandbox Code Playgroud) 如何在Symfony中创建ViewHelper 2.我阅读了整个文档,但它没有描述任何类似的术语.它只是自动加载和服务. http://symfony.com/doc/current/cookbook/index.html