小编Jua*_*nZe的帖子

Java中的NoClassDefFoundError:com/google/common/base/Function

当我执行以下代码时:

public static void main(String[] args) {
    try {
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("http:www.yahoo.com");
    } catch (NoClassDefFoundError ex) {
        System.out.println("error: " + ex.getStackTrace());
    }
}
Run Code Online (Sandbox Code Playgroud)

我遇到以下错误:

错误:[Ljava.lang.StackTraceElement; @ 80f4cb

线程"main"中的异常java.lang.NoClassDefFoundError:com/google/common/base/Function


有人可以帮我找到解决方案或原因吗?

java runtime-error selenium-webdriver

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

默认情况下,Java构造函数不公开吗?

我在两个不同的包中有两个类.对于一个类,我已经定义了一个构造函数而没有为它设置访问修饰符.我想在另一个包中实例化该类的对象并获取错误' the constructor xxx() is not visible'.

如果我定义访问修改为public它是好的.我认为构造函数默认是公开的?

java constructor visibility

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

"Object [] x"和"Object x []"之间有什么区别吗?

我正在用Java更新遗留代码库,我找到了这样的一行:

Object arg[] = { new Integer(20), new Integer(22) };
Run Code Online (Sandbox Code Playgroud)

那条线引起了我的注意,因为我习惯了这种代码:

Object[] arg = { new Integer(20), new Integer(22) };
Run Code Online (Sandbox Code Playgroud)

这里的数组内容并不重要.我很好奇变量名旁边的括号与类名旁边的括号.我在Eclipse(使用Java 5)中尝试过,这两行对编译器都有效.

这些声明之间有什么区别吗?

java arrays declaration

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

自动装配Jdbc模板

我试图自动连接JDBC模板,我得到一个空指针异常(模板为空).可能是什么问题呢?

@Autowired
template JdbcTemplate;
Run Code Online (Sandbox Code Playgroud)

这是我的应用程序上下文xml:

<bean ..>
    <mvc:annotation-driven />

            <context:component-scan base-package="igate.dto" />
                <context:component-scan base-package="igate.dao" />
                    <context:component-scan base-package="igate.service" />
                        <context:component-scan base-package="igate.controller" />
                <context:component-scan base-package="igate.logs" />
                    <context:component-scan base-package="igate.testcases" />


    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="prefix" value="/"/>
          <property name="suffix" value=".jsp" />
            </bean> 


    <bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@172.21.17.5:1521:oraten" />
        <property name="username" value="lab01trg21" />
        <property name="password" value="lab01oracle" />
    </bean>

    <bean id="template" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="ds"/>
    </bean>

</beans>
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc jdbctemplate

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

域对象,工厂和存储库之间的依赖关系

好的,我读了很多关于存储库模式的东西,包括Fowler的书.我知道它是什么以及它做了什么,但是我不太确定它是如何被工厂和/或域对象调用的.

我理解的是,存储库应该像域对象的内存中集合一样,而工厂是负责实例创建的类: new myDomainObject()

考虑到这一点,很明显存储库需要引用工厂来从数据源查询创建新对象.(存储库 - >工厂)

域对象还需要对工厂的引用才能创建新对象.

我的困境是当域对象想要检索现有对象时,它应该调用存储库还是工厂?如果直接调用库(域 - >库 - >厂),比它需要有两到工厂和仓库,这似乎太给我的参考,但它是坏?

另一方面,如果它像工厂一样调用工厂factory.CreateObjectWithId(id),那么工厂必须只将调用重定向到存储库repository.GetById(id),最后这个调用同一工厂的另一个方法来创建对象(如果它不在内存中)factory.CreateObject(dataset),因此导致循环引用:域对象 - >工厂< - >存储库,这对我来说似乎不是一件好事.

那么在您看来哪些选项更好?或者还有其他选择吗?

domain-driven-design factory repository

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

Java中的类继承问题,有和没有参数的构造函数

我正在学习Java(二年级IT学生),我遇到了一些问题.继承要准确.这是代码:

class Bazowa
    {
    public Bazowa(int i)
        {
        System.out.println("konstruktor bazowy 1");
        }

    public Bazowa(int j, int k)
        {
        System.out.println("konstruktor bazowy 2");
        }
    }

class Pochodna extends Bazowa
    {
    /* Pochodna()
        {
        System.out.println("konstruktor pochodny bez parametru");
        } */
    Pochodna(int i)
        {
        super(i);
        System.out.println("konstruktor pochodny z parametrem");
        }
    }
Run Code Online (Sandbox Code Playgroud)

因此,Pochodna类扩展了Bazowa类,我的练习是创建一个超类,它只包含带参数的构造函数和一个具有两种类型(有和没有)的子类.

当我在Pochodna课程中评论第一个构造函数时,一切正常,但我真的不知道如何在不评论该部分的情况下使其工作.我想我必须以某种方式从第一个调用构造函数,但不知道如何做到这一点.

保罗,任何帮助都会受到赞赏

java oop inheritance class

4
推荐指数
1
解决办法
2148
查看次数

如何通过Java更新LDAP时指定哈希算法?

有没有办法指定使用Java API更新Open LDAP目录时用于存储密码的哈希算法(MD5,SHA1等),代码如下:

private void resetPassword(String principal, String newPassword) throws NamingException {
InitialDirContext ctxAdmin = null;
    Hashtable<String, String> ctxData = new Hashtable<String, String>();
    ctxData.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    ctxData.put(Context.PROVIDER_URL, "ldap://myserver:389");
    ctxData.put(Context.SECURITY_AUTHENTICATION, "simple");
    ctxData.put(Context.SECURITY_PRINCIPAL, "admin_dn");
    ctxData.put(Context.SECURITY_CREDENTIALS, "admin_passwd");
    InitialDirContext ctxAdmin = new InitialDirContext(ctxData);
    if (newPassword == null || newPassword.equals("")) {
        String msg = "Password can't be null";
        throw new NamingException(msg);
    } else {
        if (principal == null || principal.equals("")) {
            String msg = "Principal can't be null";
            throw new NamingException(msg);
        } else {
        if (ctxAdmin …
Run Code Online (Sandbox Code Playgroud)

java hash ldap

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

使用Ksoap2中的Web服务传递数组

我必须调用一个Web服务,其中通过kSoap2方法调用Web服务,现在在这个节点中是一个数组,所以我可以如何传递它.

POST /opera/OperaWS.asmx HTTP/1.1
Host: 182.71.19.26
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/SendGroupMessageNotification"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SendGroupMessageNotification xmlns="http://tempuri.org/">
      <reciverMemberId>
        <Group>
          <groupid>string</groupid>
          <groupMembers>
            <Id>string</Id>
            <Id>string</Id>
          </groupMembers>
        </Group>
        <Group>
          <groupid>string</groupid>
          <groupMembers>
            <Id>string</Id>
            <Id>string</Id>
          </groupMembers>
        </Group>
      </reciverMemberId>
      <MemberId>int</MemberId>
      <MESSAGE>string</MESSAGE>
      <CREATEDDATE>string</CREATEDDATE>
      <isUrgent>boolean</isUrgent>
      <Predifnemessage>string</Predifnemessage>
    </SendGroupMessageNotification>
  </soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)

所以在上面的Web服务中,我如何设置reciverMemberId的值

使用propertyInfo可以轻松设置剩余参数.

为此,我做了一些代码如下

static class Group implements KvmSerializable
    {
        String groupid;
        Vector groupMembers;
        public Group(String groupId,Vector groupmembers)
        {
            this.groupid=groupId;
            this.groupMembers=groupmembers;
        }

        public Object getProperty(int i)
        {
            switch(i)
            {
                case 0:
                    return groupid;
                case …
Run Code Online (Sandbox Code Playgroud)

java web-services ksoap2

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

分裂一个字符串

我想取下面的代码并将我输入的5个数字字符串放入框中,并在每个数字之间输出5个空格.所以我可以进入12345,输出就是1 2 3 4 5.

我不知道如何做到这一点,或者在哪里插入代码.

String number;

while (true)
{
number = JOptionPane.showInputDialog("Enter Number");       

if(number.length() >5 )
{
JOptionPane.showMessageDialog(null,"Please enter a 5 digit number!","Try again",
        JOptionPane.PLAIN_MESSAGE);
    }
else break;
}
JOptionPane.showMessageDialog(null,"The new result is " + number,"Results",
        JOptionPane.PLAIN_MESSAGE);

        System.exit(0);
Run Code Online (Sandbox Code Playgroud)

谢谢

java split

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