小编Bhe*_*ung的帖子

我得到一个ClassCastException事件虽然类型是相同的.为什么?

我对Java并不太新,虽然我以前从未真正使用过Sets,所以有人可以帮助我吗?

我有以下问题; 但首先,这是我的代码:

HashMap<Position[], String> save = io.getSave();

Position[][] saved_pos = (Position[][]) save.keySet().toArray();
Run Code Online (Sandbox Code Playgroud)

虽然在第二行,Java抛出了ClassCastException,但为什么呢?显然,返回的Array save.keySet().toArray()确实包含Position[][]s,尽管不幸的是,toArray()在类Set中只返回一个Object[]数组.

那么我能做什么,我需要投这个.

java casting exception class

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

Java连接到多个数据库

我正在创建一个连接多个数据库的Java应用程序。用户将能够从下拉框中选择要连接的数据库。

然后,该程序将名称传递给创建初始上下文的方法,从而连接到数据库,从而可以与oracle Web逻辑数据源进行通讯。

public class dbMainConnection {

    private static dbMainConnection conn = null;
    private static java.sql.Connection dbConn = null;
    private static javax.sql.DataSource ds = null;
    private static Logger log = LoggerUtil.getLogger();

    private dbMainConnection(String database) {

         try {

            Context ctx = new InitialContext();

            if (ctx == null) {
                log.info("JDNI Problem, cannot get InitialContext");
            }

                database = "jdbc/" + database;
                log.info("This is the database string in DBMainConnection" + database);
                ds = (javax.sql.DataSource) ctx.lookup (database);


        } catch (Exception ex) {
            log.error("eMTSLogin: Error in …
Run Code Online (Sandbox Code Playgroud)

java oracle weblogic jdbc

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

基于符号拆分字符串

我正在尝试根据第二次出现的符号将字符串拆分为数组 _

var string = "this_is_my_string";
Run Code Online (Sandbox Code Playgroud)

我想在第二个下划线之后拆分字符串.字符串并不总是相同,但它总是有2个或更多下划线.我总是需要将它拆分为第二个下划线.

在上面的示例字符串中,我需要像这样拆分它.

var split = [this_is, _my_string];
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

,在$ .ajax()中抛出一个错误

我认为我完全有许多变量,但我完全没有它们,因为它们对于接收POST数据的控制器都是至关重要的.

它破坏了tv:tv,PHP Eclipse将其变为红色,但并没有告诉我问题是什么.Chromes控制台说出了意想不到的标识符.这里发生了什么?

我在这些问题中到处寻找,我找不到这样的东西.

我该如何解决它仍然使用所有这些表单字段?

$.ajax({
    type: 'POST',
    url: $('.pa-details-submit ul li a').attr('href'),
    data: {
        make_active_check: make_active_check,
        details_title: details_title,
        details_country: details_country,
        details_desc: details_desc,
        details_price: details_price,
        details_zipcode: details_zipcode,
        details_state: details_state,
        details_city: details_city,
        details_add: details_add,
        details_hidden: details_hidden,
        featured: featured,
        bedrooms: bedrooms,
        baths: baths,
        beds: beds,
        floor: floor,
        sleeps: sleeps,
        couches: couches,
        door: door,
        laundry: laundry,
        dishwasher: dishwasher,
        furnished: furnished,
        elevator: elevator,
        mon: mon,
        tue: tue,
        wed: wed,
        thu: thu,
        fri: fri,
        sat: sat,
        sun: sun,
        pets_allowed: pets_allowed,
        cabletv: cabletv,
        tv: tv,
        wireless_net, …
Run Code Online (Sandbox Code Playgroud)

ajax jquery

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

我有一个整数列表,如何排序?

有一个整数列表

List<Integer> l = new ArrayList<Integer>();
Run Code Online (Sandbox Code Playgroud)

我认为调用l.contains很慢,如何对列表进行排序.排序后,会l.contains表现得更快吗?

有没有我可以直接使用的sortedList?

java

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

Java - 在其构造函数中实例化同一类的对象

为什么在其构造函数中实例化同类的对象会抛出StackOverflowError?例如 ,

public class A {
    public A () {
        A a = new A() 
    }
}
Run Code Online (Sandbox Code Playgroud)

会抛出StackOverFlowError

java stack-overflow constructor

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

如何在Java中使用本地化时完整显示年份?

private String setDate(int day) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, + day);
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    String formattedDate = df.format(cal.getTime());
    return formattedDate;
}
Run Code Online (Sandbox Code Playgroud)

上述方法返回"14/06/12" Locale.UK和"06/14/12" Locale.US.

我怎样才能让它全年返回,即"14/06/2012"为美国语言环境,"06/14/2012"为英国语言环境?

java date date-format

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

与C++相比,为什么在覆盖时不能缩小方法可见性?

以下程序失败:

abstract class A {
  protected void method() {}
}

class B extends A {
  private void method() {}
}

public class main{
     public static void main(String []args) {}
}
Run Code Online (Sandbox Code Playgroud)

有:

main.java:6: error: method() in B cannot override method() in A
  private void method() {}
               ^
  attempting to assign weaker access privileges; was protected
1 error
Run Code Online (Sandbox Code Playgroud)

将派生方法设置为protected/private.

问题:Java不允许您进一步限制子类中的访问权限的原因是什么?我将此与C++形成对比,C++具有完全相反的规则.

java oop inheritance

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

如何更改以下代码以不使用eval?

var settings = {};

$(".js-gen-settings").each(function(){
    var date;

    if (($(this).attr("type") === "checkbox") || ($(this).attr("type") === "radio")){//if its a checkbox
        eval("settings."+this.name+" = "+$(this).is(":checked"));
    }else{
        date = $(this).val();
        if (date == ""){
            eval("settings." + this.name + " = null");
        }else{
            eval("settings." + this.name + " = '" + date + "'");
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

将使用ajax将一个JSON.stringify版本settings发送到服务器.

javascript json eval

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

接口的引用可以= null 吗?

我刚才在一本书上读到了这段代码。

public class AdapterWrapper implements ListAdapter {
  ListAdapter delegate=null;

  // other code

}
Run Code Online (Sandbox Code Playgroud)

ListAdapter是一个公共接口,并且已创建该接口的引用并将其分配为 null。这是有效的吗?我对此真的很困惑。

java android interface reference

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