Getting NumberFormatException with Hedera Java SDK setup

107 Views Asked by At

I am stuck at one point. The function call is not able to read data from .env file.

This is the main file:

 public static void main(String[] args) throws HederaReceiptStatusException, TimeoutException, HederaPreCheckStatusException {

        //Grab your Hedera testnet account ID and private key
        AccountId myAccountId = AccountId.fromString(Dotenv.load().get("MY_ACCOUNT_ID"));
        PrivateKey myPrivateKey = PrivateKey.fromString(Dotenv.load().get("MY_PRIVATE_KEY")); 
......

This is the .env file:


MY_ACCOUNT_ID=TESTNET ACCOUNT ID(0.0.1755600)
MY_PRIVATE_KEY=TESNET PRIVATE KEY(302e020100300506032b657004220420c802435424acd5c73733473532551277503ffd4dcccd1042fc657907828708a5)
2

There are 2 best solutions below

0
On

It seems that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.

Please refer java docs for NumberFormatException

4
On

Try changing your .env file to look similar to as follows:

MY_ACCOUNT_ID=0.0.1755600
MY_PRIVATE_KEY=302e020100300506032b657004220420a802435424acd5c73733473532551277503ffd4dcccd1042fc659907828708a5

refer docs