java.lang.NumberFormatException

时间:2013-06-24 07:50:14

标签: java cassandra

我有以下java代码与cassandra连接。它给出了java.lang.NumberFormatException

任何想法?

package com.retail;

import org.apache.cassandra.thrift.*;
import org.apache.thrift.protocol.*;
import org.apache.thrift.transport.*;

import java.lang.*;

public class ShowKeyspaces {

public static void main(String args[]) throws Exception {

    String host = System.getenv("localhost");
    int port = Integer.parseInt(System.getenv("9160"));

    TSocket socket = new TSocket(host,port);
    TTransport transport = new TFramedTransport(socket);

    TProtocol proto = new TBinaryProtocol(transport);
    transport.open();

    Cassandra.Client client = new Cassandra.Client(proto);

    System.out.println("Version: "+client.describe_version());
    System.out.println("cluster name : "+client.describe_cluster_name());

    transport.close();  
    }

}

它给出的错误是:

**Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.retail.ShowKeyspaces.main(ShowKeyspaces.java:14)**

知道我应该怎么做这个???

谢谢!

1 个答案:

答案 0 :(得分:2)

由于这一行,你得到NumberFormatException

int port = Integer.parseInt(System.getenv("9160"));

我认为你没有将 9160 设置为系统属性,System.getenv("9160")返回一个空字符串,即“”。所以set 9160 as an environment变量或简单地:

int port = 9160;