小编HpT*_*erm的帖子

如何在测试执行期间从assets文件夹访问文件?

如何在单元测试执行期间从assets文件夹访问文件?我的项目是使用Gradle构建的,我使用Robolectric来运行测试.似乎gradle正在认识到assets:

在此输入图像描述

这就是我在努力阅读文件的方式:

public String readFileFromAssets(String fileName) throws IOException {
    InputStream stream = getClass().getClassLoader().getResourceAsStream("assets/" + fileName);
    Preconditions.checkNotNull(stream, "Stream is null");
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
    return IOUtils.toString(reader);
}
Run Code Online (Sandbox Code Playgroud)

stream总是如此null.我尝试了许多不同的方法,即使用不同的方法定义文件的路径.

非常感谢你提前.

android gradle android-assets robolectric

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

在swift中添加UIBarButton项

我正在尝试将UIBarButton项添加到导航栏.

这是我的导航栏类声明:

import UIKit

class NavigationBarController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        configureToolbar()        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // #pragma mark - Navigation bar data source

    func configureToolbar() {
        let toolbarButtonItems = [
            searchBarButtonItem
        ]
        toolbar.setItems(toolbarButtonItems, animated: true)
    }

    var searchBarButtonItem: UIBarButtonItem {
        return UIBarButtonItem(barButtonSystemItem: .Search, target: self, action: "barButtonItemClicked:")
    }
}
Run Code Online (Sandbox Code Playgroud)

编译器没有错误,但我得到的只是一个简单的导航栏.

如何显示UIBarButtonItem?

uibarbuttonitem swift ios8

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

来自SwingWorker的jProgressBar更新

我用来通过更新ProgressBar来监视长时间运行的任务.长时间运行的任务当然是在Swingworker线程中执行的.

我曾经编程过这样的事情:

public class MySwingWorkerClass extends SwingWorker<Void, Void> {   
    private JProgressBar progressBar;    

    public MySwingWorker(JProgressBar aProgressBar) {        
        this.progressBar = aProgressBar;           
        progressBar.setVisible(true);        
        progressBar.setStringPainted(true);
        progressBar.setValue(0);        
    }

    @Override
    public Void doInBackground() {
        //long running task
        loop {  
            calculation();
            progressBar.setValue(value);
        }
        return null;
    }    

    @Override
    public void done() {                
        progressBar.setValue(100);
        progressBar.setStringPainted(false);
        progressBar.setVisible(false);      
   }
}
Run Code Online (Sandbox Code Playgroud)

但最近我发现我可以通过使用"setProgress"并定义属性更改并执行类似的操作来实现

public class MySwingWorkerClass extends SwingWorker<Void, Void> {   
    private JProgressBar progressBar;    

    public MySwingWorker(JProgressBar aProgressBar) {        
        addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if ("progress".equals(evt.getPropertyName())) {
                    progressBar.setValue((Integer) evt.getNewValue());
                }
            }
        }); …
Run Code Online (Sandbox Code Playgroud)

java swing swingworker progress-bar

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

Delphi(XE2)Indy(10)多线程Ping

我有一个有60台计算机/设备的房间(40台计算机和20台基于Windows CE的示波器),我想知道哪个和每个人都在使用ping.首先我写了一个标准的ping(请参阅此处Delphi Indy Ping错误10040),现在工作正常,但大多数计算机脱机时需要很长时间.

所以我要做的就是编写一个MultiThread Ping,但我很挣扎.我在互联网上看到的例子很少,没有人能满足我的需求,这就是为什么我自己尝试写这个例子.

我使用XE2和Indy 10,表单只包含备忘录和按钮.

unit Main;

interface

uses
  Winapi.Windows, System.SysUtils, System.Classes, Vcl.Forms,
  IdIcmpClient, IdGlobal, Vcl.StdCtrls, Vcl.Controls;

type
  TMainForm = class(TForm)
    Memo1: TMemo;
    ButtonStartPing: TButton;
    procedure ButtonStartPingClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TMyPingThread = class(TThread)
  private
    fIndex : integer;
    fIdIcmpClient: TIdIcmpClient;
    procedure doOnPingReply;
  protected
    procedure Execute; override;
  public
    constructor Create(index: integer);
  end;

var
  MainForm: TMainForm;
  ThreadCOunt : integer;

implementation

{$R *.dfm}

constructor TMyPingThread.Create(index: integer);
begin
  inherited Create(false); …
Run Code Online (Sandbox Code Playgroud)

delphi multithreading ping indy tthread

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

android - 长按一下从ListView中删除项目

我在尝试从长按一下从列表视图中删除项目时遇到了一些麻烦.以下是代码:

public class MListViewActivity extends ListActivity {

private ListView lv;
private String[] some_data = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    some_data = getResources().getStringArray(R.array.mdata);

    // Bind resources Array to ListAdapter
    ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(this,
            R.layout.list_item, R.id.label, some_data);
    this.setListAdapter(myAdapter);

    lv = getListView();
    lv.setDividerHeight(3);

    lv.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view,
                int arg2, long arg3) {

            // Can't manage to remove an item here

            return false;
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏

android android-arrayadapter android-listview

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

在点击UITextField时在UIActionSheet中显示UIDatePicker

我正在创建报警应用程序.我想UIDatePickerUIActionSheet点击时显示UITextField.

iphone objective-c ios4 ios

8
推荐指数
2
解决办法
9632
查看次数

Java JDK 32位对64位

我正在创建一个非常简单的应用程序,它可以读取和显示文本文件并搜索它们.

我问自己是否有兴趣向用户提出32位和64位版本.

区别仅在于使用64位版本访问更多内存堆大小还是有其他兴趣?

32位编译程序是否可以在64位JVM上运行(我假设是)

java 32bit-64bit

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

alertdialog里面的AlertDialog

我想一个alertdialog.But无法看到第二alertdialog..please帮助我在这里内添加alertdialog是我的代码所示

AlertDialog alertDialog = new AlertDialog.Builder(myclass.this).create();
alertDialog.setTitle("First alert");
alertDialog.setMessage("first alert press");
alertDialog.setButton("ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        // here you can add functions
        dialog.cancel();

        AlertDialog alertDialog1 = new AlertDialog.Builder(myclass.this).create();
        alertDialog1.setTitle("second alert dialog");
        alertDialog1.setMessage("second alert dialog details");
        alertDialog1.setButton("Scan Another", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int which) {
}}); }
Run Code Online (Sandbox Code Playgroud)

android android-alertdialog

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

Java HTMLDocument(insertAfterEnd,insertAfterStart,insertBeforeEnd,insertBeforeStart)无法正常工作?

我有一个JEditorPane显示以编程方式生成的HTML(在运行时).到目前为止,当我添加"行"时,我在字符串缓冲区中重新创建整个HTML文本,然后将其传递给JEditorPane.setText方法.

现在创建的HTML变得非常大(可以达到几MB),我只想在最后添加我的新行,而不是重新生成所有HTML文本.

我试图在最后追加的原因是为了避免Swing(或套件?)必须再次渲染/解析整个文本.因为即使HTML生成不是在EDT中执行,而是在另一个swingworker线程中执行,"渲染"也需要很长时间.或者最好的是有一个显示渲染进度的进度条,这是不可能的(是吗?).

所以我的想法是简单地追加到最后,但如果你有更好的想法,欢迎!

由于我的文本是在HTML表格中格式化的,我想在此表的末尾附加我的新文本.为此,我尝试使用它insertBeforeEnd,HTMLDocument但即使我尝试了大量的解决方案,我也无法使它工作.请注意,我只有"table"标签.

这是我的代码的一部分

JEditorPane jep = new JEditorPane();
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();

jep.setEditorKit(kit);
jep.setDocument(doc);

//setting dummy text within a HTML table
jep.setText("<table><tr><td>A line of text</td></tr><tr><td>Another line of text</td></tr></table>");
Run Code Online (Sandbox Code Playgroud)

现在在这个表的末尾添加一些文本

//getting the Table Element
Element e = doc.getElement(doc.getDefaultRootElement(), StyleConstants.NameAttribute, HTML.Tag.TABLE);
Run Code Online (Sandbox Code Playgroud)

请注意,该元素似乎正确找到System.out.println(e.getName())"表"

现在

//inserting text at the end of the table
try {
        doc.insertBeforeEnd(e, "<tr><td>A New Line</td></tr>");
    } catch (BadLocationException ex) {
        System.out.println(ex); …
Run Code Online (Sandbox Code Playgroud)

java swing dom jtextpane jeditorpane

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

Delphi Indy Ping错误10040

我有一小段代码通过ping它来检查计算机是否处于活动状态.我们用一个有40台电脑的房间,我想通过我的程序远程检查哪个还活着.

因此我用indy编写了一个小ping函数

function TMainForm.Ping(const AHost : string) : Boolean;
var
  MyIdIcmpClient : TIdIcmpClient;
begin
  Result := True;

  MyIdIcmpClient := TIdIcmpClient.Create(nil);
  MyIdIcmpClient.ReceiveTimeout := 200;
  MyIdIcmpClient.Host := AHost;

  try
    MyIdIcmpClient.Ping;
    Application.ProcessMessages;
  except
    Result := False;
    MyIdIcmpClient.Free;
    Exit;
  end;
  if MyIdIcmpClient.ReplyStatus.ReplyStatusType <> rsEcho Then result := False;

  MyIdIcmpClient.Free;
end;
Run Code Online (Sandbox Code Playgroud)

所以我已经在家里开发了我的wifi网络,并且工作正常.

当我重新开始工作时,我进行了测试,并且收到错误消息

Socket Errod # 10040 Message too long
Run Code Online (Sandbox Code Playgroud)

在工作中我们有固定的IP和所有的计算机,我在同一个子网中.

我试图断开与固定IP的连接并连接到wifi当然是DHCP而不是在同一个子网中,它只是工作正常.

我试过在互联网上搜索此错误以及如何解决它但没有找到太多信息.

当然我已经尝试将默认缓冲区大小更改为更大的值,但它没有改变任何东西我仍然在同一子网内的固定IP上得到错误.

此外,我不知道这是否有助于找到解决方案,但我的代码处理异常,但在这种情况下,提高错误大约需要3-4秒,而Timeout设置为200毫秒.而且我不能等待每一次ping.

顺便说一句,我使用delphi 2010,我认为它是indy 10.我也测试了XE2但是同样的错误.

任何的想法

-----编辑-----

这个问题得到了解答,现在我尝试在多线程中运行这个问题,我又问了另一个问题: Delphi(XE2)Indy(10)Multithread Ping

delphi ping indy10

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