小编abl*_*abl的帖子

是否有标准的java异常类,意味着"找不到对象"?

考虑以下一般形式的功能:

Foo findFoo(Collection<Foo> foos, otherarguments)
throws ObjectNotFoundException {
    for(Foo foo : foos){
        if(/* foo meets some condition*/){
            return foo;
        }
    }
    throw new ObjectNotFoundException();
}
Run Code Online (Sandbox Code Playgroud)

例如,一个具体的案例是:

User findUserByName(Collection<User> users, String name)
throws ObjectNotFoundException {
    for(User user : users){
        if(user.getName().equals(name)){
            return user;
        }
    }
    throw new ObjectNotFoundException();
}
Run Code Online (Sandbox Code Playgroud)

如果找不到对象,这些函数会抛出异常.我可以为此目的创建一个自定义异常类(在示例中ObjectNotFoundException),但我更喜欢使用现有的类.但是,我在标准java库中找不到具有此含义的任何异常类.您知道是否有可以在这里使用的标准例外吗?

java exception standard-library

57
推荐指数
4
解决办法
6万
查看次数

@extending bootstrap 时找不到选择器

我正在开始我的第一个 Rails 项目。在这个项目中,我将使用 Bootstrap 和 SASS。我想避免(在大多数情况下)将与样式相关的类放入我的 HTML 中,如本文所述:

使用 Sass 在语义上@extend Bootstrap

我使用 Bower 并按照此处的说明将 bootstrap-sass 包含在我的项目中:

https://github.com/twbs/bootstrap-sass#bower-with-rails

现在 bootstrap 本身正在工作,因为我可以在我的 HTML 中使用它的类,并且一切都呈现得很好。但是,如果我尝试使用 Bootstrap 类扩展我的一个类,例如:

.myClass
  @extend .text-muted
Run Code Online (Sandbox Code Playgroud)

然后我收到以下错误:

".myClass" failed to @extend ".text-muted".
The selector ".text-muted" was not found.
Use "@extend .text-muted !optional" if the extend should be able to fail.
Run Code Online (Sandbox Code Playgroud)

我想这可能与我在 Bootstrap 之前加载的 Sass 文件有关,但我不知道该怎么做。

以下是我的application.css.sass文件的内容,其中有些是*= required,有些是@imported(不知道是不是应该这样处理)。

/*
 *= require components-font-awesome
 *= require_self
 *= require_tree .
 */
$icon-font-path: "bootstrap-sass/assets/fonts/bootstrap/"
@import "bootstrap-sass/assets/stylesheets/bootstrap-sprockets"
@import …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails sass twitter-bootstrap bootstrap-sass

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

javascript中调用对象和函数之间的区别

我正在写两个文件 - 一个是html,一个是JavaScript.所以要调用我做的对象

 document.getElementById("nameObj").onmouseover = changeMe;
Run Code Online (Sandbox Code Playgroud)

在我做的JavaScript文件中

changeMe = function()
{
 //and here i write the function
}
Run Code Online (Sandbox Code Playgroud)

但现在我正在尝试优化我的代码并调用一个包含对象的函数.我创建了部分(其中4个),我正在尝试用onmouseover和更改颜色onmouseout.这是html的代码:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style.css">
        <script src="script.js"> </script>
        <title> test 2</title>
    </head>
    <body>
        <header> </header>
        <div id="wrapper">
        <main>
        <section class="mysection" id="section1"> </section>
        <section class="mysection" id="section2"> </section>
        <section class="mysection" id="section3"> </section>
        <section class="mysection" id="section4"> </section>
        </main>
        <div class="clear"> </div>
        </div>
        <footer> </footer>
                <script>
            (function(){
                var sec = document.getElementsByClassName("mysection");
                for(var i=0; i<3; i++)
                {
                    sec[i].onmouseover=changeMe(sec[i], i);
                    sec[i].onmouseout=changeBack(sec[i]); …
Run Code Online (Sandbox Code Playgroud)

html javascript onmouseover onmouseout

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

减少AJAX发出的服务器请求

我有一个滑块组件,它调用AJAX请求来根据滑块指向的值更新表.

在我的本地服务器上,没有实现延迟功能似乎很好,但是自从将我的代码部署到云服务后,我注意到当用户滑动时发送到服务器的请求数量会产生大量的延迟.

我目前的代码:

$( "#psi_slider" ).slider({
    range: "min",
    value:0,
    min:0,
    max:max_psi, 
    slide: function(event, ui) {
        update_results(json, get_values());
    }
});
Run Code Online (Sandbox Code Playgroud)

任何人都可以建议我如何在请求之间实现一个计时器,即每秒发送一个请求?

ajax jquery

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

为什么不返回值?

public class Test {

    public String xyz(){
        String name="stack";
        return name;
    }

    public static void main(String[] args) {

        Test t=new Test();
        t.xyz(); //this should stack isn't it??
    }
}
Run Code Online (Sandbox Code Playgroud)

java

-6
推荐指数
1
解决办法
51
查看次数