小编Che*_*eng的帖子

我可以避免这种繁琐的尝试......捕获块

通常,在处理Java IO代码时,这是我写的

    FileOutputStream out = null;
    try
    {
        out = new FileOutputStream("myfile.txt");
        // More and more code goes here...
    }
    catch (Exception e)
    {
    }
    finally 
    {
        // I put the close code in finally block, to enture the opened
        // file stream is always closed even there is exception happened.
        if (out != null) {
            // Another try catch block, troublesome.
            try {
                out.close();
            } catch (IOException ex) {
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,当我尝试关闭文件流时,我需要处理另一个try ... catch块.

看起来很麻烦:(

有什么办法可以避免吗?将close代码放在非finally块中感觉不舒服,因为其他代码引起的异常将无法调用"close".

java

18
推荐指数
2
解决办法
2190
查看次数

TortoiseHg - 如何在没有提交的情况下创建补丁

当我想在我的本地变更集上创建一个补丁时,我真的必须先提交,任何我都可以创建补丁.我可以在TortoiseHg下知道如何在不执行提交的情况下创建补丁吗?

tortoisehg

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

刷新iventory时出错(查询商品价格).(回复:6:错误)

我面临的问题完全相同

应用内结算v3无法在没有网络连接或飞机/飞行模式下查询项目

它并不总是发生.您需要将手机切换到飞行模式,或关闭wifi,等待几个小时,只会出现问题.将显示以下错误消息.

无法查询iventory:IabResult:刷新iventory时出错(查询商品价格).(回复:6:错误)

作者建议使用

List<String> skulist = new ArrayList<String>();
skulist.add("my_sku_name1");
skulist.add("my_sku_name2");
mHelper.queryInventoryAsync(true, skulist, mGotInventoryListener);
Run Code Online (Sandbox Code Playgroud)

解决问题.

但是,它对我不起作用.同样的问题仍然存在.

有关此问题的任何解决方法吗?谢谢.

android

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

appdata范围内无法更新文件存储 - 500内部服务器错误

以前,我有一套Google Drive API代码,在以下情况下可以正常使用

  1. 将新文件保存到appdata
  2. 在appdata中更新以前的文件
  3. 将新文件保存到非appdata
  4. 更新非appdata中的上一个文件

几天前,我遇到方案2不再工作(更新appdata中的上一个文件),而其他方案仍然没有问题.我将得到以下异常.

com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server Error
{
  "code": 500,
  "errors": [
    {
      "domain": "global",
      "message": "Internal Error",
      "reason": "internalError"
    }
  ],
  "message": "Internal Error"
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
    at org.yccheok.jstock.gui.Utils.updateFile(Utils.java:1414)
Run Code Online (Sandbox Code Playgroud)

我正在使用both DRIVEDRIVE_APPDATAscope - authorizeDrive()

代码如下

1414号线正在抛出例外情况

com.google.api.services.drive.model.File updatedFile = service.files().update(fileId, file, mediaContent).setNewRevision(false).execute();
Run Code Online (Sandbox Code Playgroud)

使用查询在appdata中搜索上一个文件title contains 'jstock-fe78440e-e0fe-4efb' and trashed = false and 'appdata' …

java google-drive-api

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

LinkedHashSet或ArrayList

我希望

  1. 避免插入重复的项目.
  2. 当我遍历集合类时,返回的项与插入顺序相同.

我可以知道,我应该考虑什么,选择ArrayList(在插入前显式执行包含检查)或LinkedHashSet?

谢谢.

java data-structures

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

Chrome Angry Bird背后有什么技术

我想知道Chrome Angry Bird背后使用的技术是什么?

它使用HTML5画布进行显示.对于编程逻辑代码,它似乎不是闪存.或者,愤怒的小鸟队在JavaScript中重写他们的代码?

google-chrome

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

获取所有可能的可用货币

我想获得所有可能的货币.

Java 7提供了这样的功能.

public static Set<java.util.Currency> java.util.Currency.getAvailableCurrencies()
Run Code Online (Sandbox Code Playgroud)

但是,我仍在使用Java 6进行开发和部署.我可以知道如何获得所有可能的货币吗?代码示例最受欢迎.

java

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

<Your App>在使用Google Play服务时出现问题 - 使用GoogleApiClient时,它始终会触发onConnectionFailed

目前,我的应用正在使用

  • minSdkVersion 14
  • targetSdkVersion 23
  • 编译'com.google.android.gms:play-services-gcm:8.4.0'
  • 编译'com.google.android.gms:play-services-base:8.4.0'
  • 编译'com.google.android.gms:play-services-analytics:8.4.0'
  • 编译'com.google.android.gms:play-services-ads:8.4.0'
  • 编译'com.google.android.gms:play-services-drive:8.4.0'

我使用以下代码来执行GoogleApiClient连接.

public class GoogleApiClientFragment extends Fragment implements
        GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    public interface ConnectionCallbacks {
        void onConnected(GoogleApiClient googleApiClient, int action);
        void onCancel(int action);
    }

    public static GoogleApiClientFragment newInstance(String accountName, int action) {
        GoogleApiClientFragment googleApiClientFragment = new GoogleApiClientFragment();
        Bundle bundle = new Bundle();
        bundle.putString(INTENT_EXTRA_ACCOUNT_NAME, accountName);
        bundle.putInt(INTENT_EXTRA_ACTION, action);
        googleApiClientFragment.setArguments(bundle);
        return googleApiClientFragment;
    }

    /**
     * Handles resolution callbacks.
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        super.onActivityResult(requestCode, resultCode, data); …
Run Code Online (Sandbox Code Playgroud)

android google-play-services google-signin

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

PHP AMQP的延迟队列的实现

最近,我在生产者/消费者队列系统上做了快速实现.

<?php
namespace Queue;

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;    

class Amqp
{
    private $connection;
    private $queueName;
    private $delayedQueueName;
    private $channel;
    private $callback;

    public function __construct($host, $port, $login, $password, $queueName)
    {
        $this->connection = new AMQPStreamConnection($host, $port, $login, $password);
        $this->queueName = $queueName;
        $this->delayedQueueName = null;
        $this->channel = $this->connection->channel();
        // First, we need to make sure that RabbitMQ will never lose our queue.
        // In order to do so, we need to declare it as durable. To do so we pass
        // …
Run Code Online (Sandbox Code Playgroud)

php amqp rabbitmq

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

Rectangle和Rectangle2D的区别

目前,我使用Rectangle和Rectangle2D(Rectangle2D.Double)交换.

我想知道在选择正确的数据类型时我会考虑什么?我没有看到任何明显的区别,除了Rectangle(Rectangle2D的子类)有更多的API函数.

谢谢.

java

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