小编Mr_*_*s_D的帖子

Maven:如何在Eclipse中包含jar,这些jar在存储库中不可用?

我已经将JAR复制到了src\main\webapp\WEB-INF\lib.
我用eclipse.如果我将jar一个一个地添加到Project-> Java Build Path-> Add jars,然后我执行Project-> Maven-> Update Project Configuration,它们将被Maven删除.Eclipse显示错误,其中包含"xxx无法解析".

Env:
Eclipse Java EE IDE for Web Developers.
Version: Indigo Service Release 1
Build id: 20110916-0149

m2e - Maven Integration for Eclipse 1.0.100.20110804-1717
Run Code Online (Sandbox Code Playgroud)

注意:我不想创建自己的Maven存储库.它只会使用一次.
我该怎么办?

java jar buildpath maven

12
推荐指数
1
解决办法
6万
查看次数

广播接收者收到的意图是否可以为空?

换一种说法 :

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction(); // can intent==null here ?
    // could it ever throw a NPE ?
}
Run Code Online (Sandbox Code Playgroud)

我需要一劳永逸地解决这个问题,所以请不要错过.我会检查null,但我怀疑它不需要,因此它是笨拙和不优雅的检查.我在文档中搜索过但没有找到任何内容

编辑:在谷歌组问-看到一些有趣的点

android nullpointerexception broadcastreceiver android-intent

12
推荐指数
1
解决办法
3500
查看次数

来自Dataset的tf.train.MonitoredTrainingSession和reinitializable迭代器

似乎MonitoredTrainingSession在第一次调用.run(..)之前做了一些操作(logging?),这意味着当我这样做时:

train_data = reader.traindata() # returns a tf.contrib.data.Dataset
it = tf.contrib.data.Iterator.from_structure(train_data.output_types, train_data.output_shapes)
init_train = it.make_initializer(train_data)
ne = it.get_next()
ts = tf.train.MonitoredTrainingSession(checkpoint_dir=save_path)

... no calls to ts.run ...

ts.run(init_train)
Run Code Online (Sandbox Code Playgroud)

这会产生错误:

FailedPreconditionError (see above for traceback): GetNext() failed because the iterator has not been initialized. Ensure that you have run the initializer operation for this iterator before getting the next element
Run Code Online (Sandbox Code Playgroud)

因此,在运行我提供的操作之前,它就像MonitoredTrainingSession正在执行某些操作一样接缝,从而无法使用来自Dataset的可重新初始化的迭代器进行togeather.

我相信我错过了一些东西,并希望听到:-)

tensorflow tensorflow-datasets

12
推荐指数
1
解决办法
1963
查看次数

为什么泛型类型参数说"扩展"可比较而不是"实现"?

我试着编写从数组中删除重复元素的泛型函数.

public static <E extends Comparable<E>> ArrayList<E> removeDuplicate(E[] arr) {
    //do quicksort
    Arrays.sort(arr);
    ArrayList<E> list = new ArrayList<E>();
    int i;
    for(i=0; i<arr.length-1; i++) {
        if(arr[i].compareTo(arr[i+1]) != 0) { //if not duplicate, add to the list
            list.add(arr[i]);
        }
    }
    list.add(arr[i]); //add last element
    return list;
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,您无法传递像int []数组这样的原始类型,因为我通过在Comparable接口中定义的compareTo()方法来比较元素.

我注意到第一行(方法声明):

public static <E extends Comparable<E>> ArrayList<E> removeDuplicate(E[] arr) {
Run Code Online (Sandbox Code Playgroud)

它怎么说"扩展可比"?

可比较是一个接口,为什么它不"实现可比"?这是我第一次编写泛型函数,所以我对这些细节感到困惑.(任何疑惑都会阻止我理解..)

编辑:发现此文章与此主题相关.

http://www.tutorialspoint.com/java/java_generics.htm

java generics comparator

11
推荐指数
2
解决办法
2万
查看次数

Qt QWEBview JavaScript回调

如何将函数"指针"从JavaScript传递到插槽?

在JavaScript中:

function f1()
{
    alert("f1");
}
qtclass.submit(f1);
Run Code Online (Sandbox Code Playgroud)

在Qt:

public slots:
    void submit(void * ptr) 
    {
        (void)ptr;
    }
Run Code Online (Sandbox Code Playgroud)

我需要"f1"函数,一旦完成某些处理,就会从c ++中激活JavaScript.另外我事先并不知道函数指针的名称.

javascript qt qwebview slot

11
推荐指数
2
解决办法
2万
查看次数

onLocationChanged不会自动调用

我在Android中的onLocationChanged事件有问题.这是触发:

case R.id.start: {
    Points.add(overlay.getMyLocation()); // Points' type is ArrayList<GeoPoint>
    mgr.requestLocationUpdates(best, 0, 3, locationListener);
    }
    break;
Run Code Online (Sandbox Code Playgroud)

这是onLocationChanged方法:

public void onLocationChanged(Location location) {
    i++;
    Points.add(overlay.getMyLocation());
    MapOverlay mapOverlay = new MapOverlay(Points.get(i-1), Points.get(i));
    map.getOverlays().add(mapOverlay); //does the drawing
    mMapController.animateTo(Points.get(i));
}
Run Code Online (Sandbox Code Playgroud)

因此,onLocationChanged仅在我按"start"后调用一次.它应该在每次位置发生变化时自动调用,对吗?就我而言,事实并非如此.
请帮我.

gps android geolocation locationmanager locationlistener

11
推荐指数
1
解决办法
3万
查看次数

Android链接到无线和网络设置

嗨,我正在制作一个检查互联网连接的应用程序,如果它没有连接,它会转到一个有错误消息的活动和一个我想链接到无线和网络设置的按钮.但我不知道怎么做,有人可以帮帮我吗?
这是我到目前为止所得到的.

public class NetworkActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.networkact);
        Button settings = (Button) findViewById(R.id.btn_settings);
        // Listening to button event
        settings.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // Starting a new Intent
                Intent gotoSettings = new Intent(getApplicationContext(),
                        HomeActivity.class);
                startActivity(gotoSettings);
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

目前它进入另一项活动,但我希望它转到无线和网络设置.

android android-wifi

11
推荐指数
2
解决办法
1万
查看次数

Argparse - 没有参数的自定义操作?

class StartAction(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        print "Hello"

start.add_argument('-s', '--start', action=StartAction)
Run Code Online (Sandbox Code Playgroud)

我知道通常让行为像'store_true'会阻止参数的要求,但是有没有办法使用自定义动作并且仍然不需要传递参数?

所以我想要的是:

python example.py -s

你好

python argparse

11
推荐指数
3
解决办法
4508
查看次数

在Python中使用file.write写入文件时出错.UnicodeEncodeError

我从来没有处理过编码和解码字符串,所以我就是这方面的新手.当我尝试使用Python中的file.write将我从另一个文件读取的内容写入临时文件时,我收到了一个UnicodeEncodeError.我收到以下错误:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 41333: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)

这是我在我的代码中所做的.我正在读取XML文件并从"mydata"标签获取文本.然后我遍历mydata寻找CDATA

    parser = etree.XMLParser(strip_cdata=False)
    root = etree.parse(myfile.xml, parser)
    data = root.findall('./mydata')
    # iterate through list to find text (lua code) contained in elements containing CDATA
    for item in myData:
        myCode = item.text

    # Write myCode to a temporary file.
    tempDirectory = tempfile.mkdtemp(suffix="", prefix="TEST_THIS_")
    file = open(tempDirectory + os.path.sep + "myCode.lua", "w")

    file.write(myCode + "\n")
    file.close()
Run Code Online (Sandbox Code Playgroud)

当我点击以下行时,它失败了UnicodeEncodeError:

file.write(myCode + "\n")
Run Code Online (Sandbox Code Playgroud)

我应该如何正确编码和解码?

unicode encode decode fwrite python-2.7

11
推荐指数
1
解决办法
9659
查看次数

使用Tensorflow构建适用于可变批量大小的图形

我使用tf.placeholders()ops来输入变量批量大小的输入,它们是2D张量,当我调用run()时,使用feed机制为这些张量提供不同的值.我有

TypeError:'Tensor'对象不可迭代.

以下是我的代码:

with graph.as_default():
    train_index_input = tf.placeholder(tf.int32, shape=(None, window_size))
    train_embeddings = tf.Variable(tf.random_uniform([vocabulary_size, embedding_dimension], -1.0, 1.0))
    embedding_input = [tf.nn.embedding_lookup(train_embeddings, x) for x in train_index_input]
    ......
    ......
Run Code Online (Sandbox Code Playgroud)

由于我无法在不运行图形的情况下看到张量"train_index_input"的内容,因此"'Tensor'对象的错误不可迭代"会引发代码:

embedding_input = [tf.nn.embedding_lookup(train_embeddings, x) for x in train_index_input]
Run Code Online (Sandbox Code Playgroud)

我想要获得的是嵌入矩阵"embedding_input",其形状[batch_size,embedding_dimension] batch_size不固定.我是否必须在Tensorflow中定义一个新操作来嵌入2D张量的查找?或者其他任何方式吗?谢谢

python tensorflow

11
推荐指数
1
解决办法
4923
查看次数