你如何Bitmap变成一个InputStream?
我想用它InputStream作为ETC1Util.loadTexture()函数的输入.
有没有办法在单元测试失败时自动启动调试器?
现在我只是手动使用pdb.set_trace(),但这非常繁琐,因为我需要每次添加它并在结束时将其取出.
例如:
import unittest
class tests(unittest.TestCase):
def setUp(self):
pass
def test_trigger_pdb(self):
#this is the way I do it now
try:
assert 1==0
except AssertionError:
import pdb
pdb.set_trace()
def test_no_trigger(self):
#this is the way I would like to do it:
a=1
b=2
assert a==b
#magically, pdb would start here
#so that I could inspect the values of a and b
if __name__=='__main__':
#In the documentation the unittest.TestCase has a debug() method
#but I don't understand how to use it
#A=tests() …Run Code Online (Sandbox Code Playgroud) 我只是没有得到traceview输出的各种元素,我找不到教程.有人可以参考下图解释以下内容:

在继续执行程序之前,我想等到Android ImageView中的动画结束*,这样做的正确方法是什么?
研究/猜测:
答:我的问题似乎是Java线程问题,因为Android AnimationDrawable实现了Java.lang.Runnable.也许线程是解决方案.也许答案会包括加入?
B.其他人的方法似乎是使用AnimationListener,这对于我的简单需求来说似乎很困难且不必要地复杂.另外,我不确定如何做到这一点.
C. AnimationDrawable类有一个(boolean)isRunning方法,它可能在while循环中使用(即while(anim.isRunning()){wait(100ms)}).但我有一种直觉,认为这是错误的做法.虽然在并发教程中似乎提到了类似的东西
代码片段
this.q_pic_view.setImageResource(0);
this.q_pic_view.setBackgroundResource(R.drawable.animation_test);
AnimationDrawable correct_animation = (AnimationDrawable) this.q_pic_view.getBackground();
correct_animation.start();
//here I tried to implement option C but it didn't work
while(correct_animation.isRunning()){
try {
Thread.sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
动画
<?xml version="1.0" encoding="utf-8"?>
<animation-list android:id="@+id/AnimTest" android:oneshot="true" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/animtest001" android:duration="33"/>
<item android:drawable="@drawable/animtest002" android:duration="100"/>
<item android:drawable="@drawable/animtest003" android:duration="66"/>
<item android:drawable="@drawable/animtest004" android:duration="66"/>
<item android:drawable="@drawable/animtest005" android:duration="33"/> …Run Code Online (Sandbox Code Playgroud) 什么是"尾部位置"的精确定义,以便在clojure中重复出现.我认为这将是循环S表达式中的最后一项,但在下面的例子中,在我看来,以(if ...)开头的S-Expression处于尾部位置即([LOOP KEYWORD] [BINDING STATMENTS] [IF声明]).
(= __
(loop [x 5
result []]
(if (> x 0)
(recur (dec x) (conj result (+ 2 x)))
result)))
Run Code Online (Sandbox Code Playgroud)
代码取自http://www.4clojure.com/problem/68
密切相关的问题:如何在Clojure中调用if条件中的recur?
你如何正确启用Logging for Apache Commons HttpClient
现在我这样做并且除了我明确触发的测试之外没有任何日志消息:
public class HttpTest1 {
static Log log = LogFactory.getLog(Class.class);
public static void main(String[] args) throws ClientProtocolException, IOException{
log.warn("Logging Works");
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
DefaultHttpClient client = new DefaultHttpClient();
HttpGet method = new HttpGet("http://www.google.com");
HttpResponse response = client.execute(method);
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
Feb 28, 2012 2:16:31 PM httpTest.HttpTest1 main
WARNING: Logging Works …Run Code Online (Sandbox Code Playgroud) 我想从自动完成之外触发一些jQuery自动完成事件,但我不知道如何.即
$("something").autocomplete({select:function(event,ui){do x},
search:function(event,ui){do y}});
$("something else").keypress(function(eventobject){*trigger autocomplete "select"*});
Run Code Online (Sandbox Code Playgroud)
我在触发器自动完成中选择了什么代码"select"
运行表单的SQL查询后:
SELECT table_name.column_name FROM table_name,table_name2,etc... WHERE condition1,condition2,etc...,
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,但没有关闭我的程序:
请求具有表名的列名 - table_name.column_name
谷歌搜索这个错误短语导致我到android.database.sqlite.SQLiteCursor线314
在314行以上的几行有一条评论,这段代码是对错误903852的回应.但我似乎无法在谷歌上找到这个错误.
所以这是一个两部分问题:
是否有java等价的python eval函数?
这将是一个函数,它接受任意字符串并尝试在当前上下文中执行它.