小编Mic*_*ers的帖子

哪种数据结构使用更多内存?

哪种类型的数据结构使用更多内存?

  • 哈希表
  • 哈希映射
  • 数组列表

你能不能给我一个简短的解释,哪一个不容易出现内存泄漏?

java memory-management data-structures

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

如何更改JButton的图像?

我正在开发一个记忆游戏程序.我在JPanel上有30个JButton.当用户点击并找到匹配项(意味着具有相同图像的两个按钮)时,我想将JButton上的图像更改为其他图像.但是,在程序运行时不会发生这种情况.

我怎样才能做到这一点?

我这样做:

cards[i].setIcon(cardBack);
Run Code Online (Sandbox Code Playgroud)

cardBack是我已经拥有的ImageIcon.

java swing jbutton

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

发送电子邮件 - 使用DB或Web应用程序

我目前正致力于指定一个软件,生成的电子邮件将成为系统的重要组成部分.

在调查中,我可以从数据库中提取我需要的所有信息,并创建带附件的电子邮件,并使用数据库的内置邮件功能(Oracle和SQL Server)发送它们.

我的另一个选择是在我的应用程序代码中生成电子邮件.

由于我不需要在电子邮件上进行任何花哨的格式化,最好的方法是什么?在实现我的目标方面似乎没有区别; 使用数据库的唯一好处是我可以设置要在更新行的触发器上发送的电子邮件.

email

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

RoR:rake db:schema:加载RAILS_ENV =生产错误

当我尝试在Rails中创建生产数据库时,我收到以下错误:

>rake db:schema:load RAILS_ENV=production --trace
rake db:schema:load RAILS_ENV=production --trace
(in C:/Users/user/Documents/Aptana Studio/truping)
** Invoke db:schema:load (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
no such file to load -- application
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:262:in `require_or_load'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:221:in `depend_on'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:133:in `require_dependency'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:18:in `define_dispatcher_callbacks'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:182:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:182:in `evaluate_method'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:166:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `each'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `send'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:277:in `run_callbacks'
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:559:in `send'
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:559:in `prepare_dispatcher'
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:173:in `process'
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in `send'
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in `run'
C:/Users/rrevi/Documents/Aptana Studio/truping/config/environment.rb:13
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require' …

ruby-on-rails

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

StackOverFlow错误 - 来自实例化我的对象类

我试图在Java中创建一个类,它构建一个类型的对象,Action它包含三个int并将它返回到我在数组中的另一个类history,其中history是一个类型的数组Action.当它被调用时,我立刻得到一个无限循环; 因此堆栈溢出.

错误 - 我打印了1行,它继续...

Exception in thread "main" java.lang.StackOverflowError
    at sudokugame.Action.<init>(Action.java:7)
Run Code Online (Sandbox Code Playgroud)

类:

public class Action {

    Action a;
    public Action(int i, int o, int p){
      a = new Action(i,o,p);
    }

    public void   setAction(int n, int b, int c){

    }

    public Action  getAction(){
        return a;
    }
}
Run Code Online (Sandbox Code Playgroud)

java stack-overflow

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

匿名类的输出?

如何从Java匿名类中获取输出?在.Net中我会使用闭包.

executor = Executors.newSingleThreadExecutor();
final Runnable runnable = new Runnable() {
  public Exception exception;

  @Override
  public void run() {
    try {
      doSomething();
    }
    catch (Exception exception) {
      // I'd like to report this exception, but how?
      // the exception member is not readable from outside the class (without reflection...)
      this.exception = exception;
    }
  }
};

executor.submit(runnable);

// Here I'd like to check if there was an exception
Run Code Online (Sandbox Code Playgroud)

java closures exception anonymous-types

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

这个功能可以更安全吗?寻找提示和你的想法!

这有点奇怪的问题.

我写了一个C函数.它的'喜欢'strchr/strrchr.它应该在c字符串中查找一个字符,但是向后移动,并返回指向它的指针.由于c字符串不是"空启动",它还需要第三个参数'count',表示它应该向后看的字符数.

/*
*s: Position from where to start looking for the desired character.
*c: Character to look for.
*count: Amount of tests to be done
*
* Returns NULL if c is not in (s-count,s)
* Returns a pointer to the occurrence of c in s.
*/
char* b_strchr(const char* s,int c,size_t count){

    while (count-->0){

        if (*s==c) return s;
        s--;
     }
     return NULL;
}
Run Code Online (Sandbox Code Playgroud)

我已经对它进行了一些测试,但是你看到它有什么缺陷吗?安全问题左右?任何增强功能?可以改进吗?更重要的是:这是一个坏主意吗?

一些用法.

    char* string = "1234567890";

    printf("c: %c\n",*b_strchr(string+9,'5',10));//prints 5

    printf("c: %c\n",*b_strchr(string+6,'1',7));//prints 1
Run Code Online (Sandbox Code Playgroud)

编辑:新界面,一些变化. …

c unsafe

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

对List <Generic> Explicit Cast的疑问

我不明白为什么在某些情况下我可以做一个明确的演员,而在其他情况下我不能.谢谢大家!

//DAreaLabel extends Message 

//This Code Works
List<Message> list1 = (List<Message>)
        Arrays.asList((Message[]) getPageRecords(getClasspath(), methodName, object));

DAreaLabel areaLabel = (DAreaLabel)
        ((List<Message>) Arrays.asList((Message[]) getPageRecords(getClasspath(), methodName, object))).get(0);

//This Code does not Work
List<DAreaLabel> list2 = (List<DAreaLabel>)
        Arrays.asList((Message[]) getPageRecords(getClasspath(), methodName, object));
Run Code Online (Sandbox Code Playgroud)

java generics casting

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

Java:通过引用传递/ ListIterator.add()

Java不通过引用传递变量.在这种情况下,数据结构如何ListIterator更改其相应的列表?

这是我写的一个示例迭代器:

public class OdpIterator<E> implements ListIterator<E> {

    private OdpList<E> list;
    private int cursor;

    public OdpIterator(OdpList<E> list) {
        this.list = list;
    }

    @Override
    public void add(E arg0) {
        list.add(arg0);
    }
Run Code Online (Sandbox Code Playgroud)

但是当我尝试更改listadd(),它不会更改基础列表,因此以下测试失败:

OdpList<Integer> list = new OdpList<Integer>();
ListIterator<Integer> iter = list.listIterator();
iter.add(42);
assertTrue(list.contains(42));
Run Code Online (Sandbox Code Playgroud)

OdpList add:我认为它是正确的,因为它通过了它的单元测试.

@Override
public boolean add(E arg0) {
    ListCell<E> cell = new ListCell<E>(arg0);

    if (size() > 0) { //if something is already in the list
        tail.setNext(cell);
        tail = cell;
    }
    else { …
Run Code Online (Sandbox Code Playgroud)

java variables iterator pass-by-reference data-structures

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

正则表达式(字母数字)

我需要一个正则表达式,允许用户输入以字母(不是数字)开头的字母数字字符串.

regex

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