小编Gam*_*ids的帖子

修改Eclipse equals()方法模板

eclipse生成的equals()方法对于if结构没有{}.例如

public boolean equals(Object obj) {
    if (this == obj)
        return true;
    .........
    return true;
}
Run Code Online (Sandbox Code Playgroud)

如何更改以在以下模式中生成代码

public boolean equals(Object obj) {
    if (this == obj){
        return true;
    }
    .........
    return true;
}
Run Code Online (Sandbox Code Playgroud)

java eclipse

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

Android - 在webview中加载PDF

我有这个webview代码,我希望能够在用户点击PDF链接时打开PDF文件.这是代码,你能告诉我我必须把它放在PDF区域吗?我已经尝试了很多不同的方法,我根本无法查看PDF.谢谢您的帮助.

webview.setWebViewClient ( new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // do your handling codes here, which url is the requested url
        // probably you need to open that url rather than redirect:
        if (url.startsWith("tel:")) {
            startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
        } else if (url.startsWith("mailto:")) {
            url = url.replaceFirst("mailto:", "");
            url = url.trim();
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("plain/text").putExtra(Intent.EXTRA_EMAIL,
                    new String[]{url});
            startActivity(i);

        } else if (url.startsWith("geo:")) {
            try {
            } catch (Exception e) {
                System.out.println(e);
            }

        } else if …
Run Code Online (Sandbox Code Playgroud)

java pdf android webview webviewclient

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

PoolingHttpClientConnectionManager中的MaxPoolSize太小时,Apache的HttpClient停止工作

我有一个SwingWorker获取URL列表的列表(可以是数百个)。在该doInBackground()方法中,它遍历这些URL,每次创建a CloseableHttpClient,由a PoolingHttpClientConnectionManager和a管理HttpGet。然后,client将执行httpGet并将内容(图像)写入文件(如果可能!并非所有URL都有效,并且某些URL返回404)。

直到达到connectionManager 的maxTotal(或defaultMaxPerRoute),这大约可以处理100个请求。然后一切都停止了,客户端的执行停止了,并且没有抛出异常。

所以我想,我将maxTotal和设置defaultMaxPerRoute1000并签出。当我尝试下载1500张图像时,它可以工作,但是感觉真不对劲!我想重用客户端,而不是在池中容纳1000个客户端。

Socket或ConnectionTimeouts无效,调试不会告诉我正在发生的事情,HttpClients而在没有该消息的情况下创建新指令PoolingHttpClientConnectionManager也不起作用。关闭客户端和/或结果也不起作用。

我应该如何管理客户端或设置池以确保我SwingWorker什至可以下载数千个图像?

我将尝试将SwingWorker代码分解为重要部分:(几乎忘了,它实际上是循环的对象列表,每个对象都有3个URL)

// this is how I init the connectionManager (outside the swing worker)
this.connectionManager = new PoolingHttpClientConnectionManager();
this.connectionManager.setMaxTotal(100);
this.connectionManager.setDefaultMaxPerRoute(100);

// this is where the images are downloaded in the swing worker
@Override
protected Void doInBackground() throws Exception{
    for(MyUrls myUrls : …
Run Code Online (Sandbox Code Playgroud)

java swingworker apache-httpclient-4.x

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

调用supplyAsync时尝试并捕获

我是CompletableFuture的新手,我想调用MetadataLoginUtil :: login方法,它可以抛出异常.但是,尽管我已经"特别"编写,但下面的代码并未编译.它说我必须在try&catch中包装MetadataLoginUtil :: login'.

请指教.谢谢!

public void run() throws ConnectionException {
    CompletableFuture<Void> mt = CompletableFuture.supplyAsync(MetadataLoginUtil::login)
            .exceptionally(e -> {
                System.out.println(e);
                return null;
            })
            .thenAccept(e -> System.out.println(e));
}
Run Code Online (Sandbox Code Playgroud)

java java-8 completable-future

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

布尔示例返回意外答案

我正在通过indiabix进行java测试,有一个布尔问题就像 -

public class If2 
{
    static boolean b1, b2;
    public static void main(String [] args) 
    {
        int x = 0;
        if ( !b1 ) /* Line 7 */
        {
            if ( !b2 ) /* Line 9 */
            {
                b1 = true;
                x++;
                if ( 5 > 6 ) 
                {
                    x++;
                }
                if ( !b1 ) /* Line 17 */
                    x = x + 10;
                else if ( b2 = true ) /* Line 19 */
                    x = …
Run Code Online (Sandbox Code Playgroud)

java boolean

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

Java代码无法访问

请查看我的代码,其显示代码无法访问.

private static void createUser() {
    HashMap<String, String> membership = new HashMap<String, String>();
    System.out.println("Enter the Name of the User: ");
    String nameOfUser=sc.next();
    System.out.println("Enter the Membership tier which you prefer");
    System.out.println("1. Member - 5 % discount \n 2. Bronze - 10 % discount \n 3. Silver - 15% discount \n "
            + "4. Gold - 20 % discount \n 5. Platinum - 25 % discount");
    String typeOfMembership = null;
    while(true){
        int memberChoice=sc.nextInt();
        switch(memberChoice){
            case 1:
                typeOfMembership="Member";
                membership.put(nameOfUser,typeOfMembership);
                break;
            case 2:
                typeOfMembership="Bronze"; …
Run Code Online (Sandbox Code Playgroud)

java

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

在秋千中使用sleep()

public class TestFrame extends JFrame
{
   public TestFrame()
   {

        setBounds(10, 10, 500, 500);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(3);       
   }

   public static void main(String[] args) throws InterruptedException
   {
        TestFrame tf = new TestFrame();
        tf.add(new JButton("test1"));
        tf.setVisible(true);
        Thread.sleep(2000);
        tf.getContentPane().removeAll();
        tf.add(new JButton("test2"));
        System.out.print("Show test");
   }
}
Run Code Online (Sandbox Code Playgroud)

我希望节目JButton("test2")在2秒后显示出来.
然后,添加thread.sleep(2000)test1.

但我不知道为什么程序停止显示test1 JButton,而不显示test2 JButton和"显示测试"消息可以成功打印出来

java swing multithreading

0
推荐指数
1
解决办法
951
查看次数

如何仅当变量在 Java 中不为 null 时才将其作为参数传递

我有以下代码存根,我正在从属性文件中读取一组值。仅当它们不为 NULL 时,我才需要使用这些值将其作为参数传递给函数。

public static void main(String[] args) {
    String arg1 = "arg1";
    String arg2 = "arg2";
    String arg3 = null;
    String arg4 = "arg4";
    .
    .
    .

    testMethod(arg1, arg2, arg3);
}

public void testMethod(String... values) {

}
Run Code Online (Sandbox Code Playgroud)

在上面的代码片段中。我想用参数 arg1、arg2、arg4 调用 testMethod() 只是因为 arg3 为 NULL。

参数的数量可能会有所不同。它不会一直是 4。

我的代码应该动态检查参数是否为 NULL 并将其传递给 testMethod()。

我可以在 Java 中实现这一点吗?如果是,有人可以帮助我..

java parameter-passing

0
推荐指数
1
解决办法
1211
查看次数

如何使用JQuery从列表中获取所有href值?

我想href用JQuery 从属性中检索所有URI .我怎么能这样做?

这是HTML的一个例子

<ul class="nav navbar-nav"> 
    <li class="active"><a href="www.myweb.com/home">Home <span class="sr-only">(current)</span></a></li> 
    <li><a href="www.myweb.com/findyourcity">Find Your City</a></li> 
    <li><a href="www.myweb.com/howitwork">How It Works</a></li> 
    <li><a href="www.myweb.com/faq">FAQ</a></li> 
</ul>
Run Code Online (Sandbox Code Playgroud)

jquery href

-3
推荐指数
1
解决办法
3957
查看次数