Home > Mobile >  Java runtime exception: always convert the result to the String
Java runtime exception: always convert the result to the String

Time:03-10

Package com. Liyinan. Mobileblockchain;

The import android. Support. V7. App. AppCompatActivity;
The import android. OS. Bundle;
The import android. OS. Handler;
The import android. OS. The Message;
The import android. View. The view;
The import android. Widget. The Button;
The import android. Widget. TextView;

The import org. Alexd. Jsonrpc. JSONRPCException;
The import org. Alexd. Jsonrpc. JSONRPCHttpClient;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



Public class MainActivity extends AppCompatActivity implements the View. An OnClickListener {

Private Button showButton.
Private TextView TextView;

Public static final ints SHOW=0;

Private Handler Handler=new Handler () {

Public void handleMessage (Message MSG) {
The switch (MSG. What) {
Case SHOW:
String a=(String) MSG. Obj;
Textview. SetText (a);
}
}
};

@ Override
Protected void onCreate (Bundle savedInstanceState) {
Super. OnCreate (savedInstanceState);
The setContentView (R.l ayout. Activity_main);
Textview=the findViewById (R.i which extview);
ShowButton=the findViewById (R.i d.s howView);
ShowButton. SetOnClickListener (this);
}

@ Override
Public void onClick (View v) {
If (v.g etId ()==R.i d.s howView) {
Show ();
}
}

Private void show () {
New Thread (new Runnable () {
@ Override
Public void the run () {
Try {
The String url="http://10.21.23.135:8545";//note, not 127.0.0.1
//the String url="http://10.0.2.2:8545";
JSONRPCHttpClient client=new JSONRPCHttpClient (url);
Map The map=new HashMap ();
The List paramsList=new ArrayList ();
The map. The put (" json RPC - ", "2.0");
The map. The put (" method ", "web3_clientVersion");
The map. The put (" params ", paramsList);
The map. The put (" id ", "67");
String st=client. CallString (" web3_clientVersion ", map);
The Message MSG=new Message ();
MSG. What=SHOW;
MSG. Obj=st;
Handler. SendMessage (MSG);
} the catch (JSONRPCException e) {
//textview. SetText (" step wrong?? ");
e.printStackTrace();
}
}
}). The start ();
}
}



Run the above code is an exception:
W/System. Err: org. Alexd. Jsonrpc. JSONRPCException: always convert the result to the String
The at org. Alexd. Jsonrpc. JSONRPCClient. CallString (JSONRPCClient. Java: 226)
At com. Liyinan. Mobileblockchain. MainActivity $2. The run (MainActivity. Java: 69)
The at Java. Lang. Thread. The run (Thread. Java: 841)
Under Caused by: org. Alexd. Jsonrpc. JSONRPCException: IO error
The at org. Alexd. Jsonrpc. JSONRPCHttpClient. DoJSONRequest (JSONRPCHttpClient. Java: 133)
The at org. Alexd. Jsonrpc. JSONRPCClient. DoRequest (JSONRPCClient. Java: 94)
The at org. Alexd. Jsonrpc. JSONRPCClient. CallString (JSONRPCClient. Java: 223)
. 2 more
Under Caused by: org. Apache. HTTP. Conn. HttpHostConnectException: Connection refused to http://10.21.23.135:8545
The at org. Apache. HTTP. Impl. Conn. DefaultClientConnectionOperator. OpenConnection (DefaultClientConnectionOperator. Java: 183)
At org. Apache. HTTP. Impl. Conn. AbstractPoolEntry. Open (164) AbstractPoolEntry. Java:
At org. Apache. HTTP. Impl. Conn. AbstractPooledConnAdapter. Open (119) AbstractPooledConnAdapter. Java:
The at org. Apache. HTTP. Impl. Client. DefaultRequestDirector. Execute (DefaultRequestDirector. Java: 360)
The at org. Apache. HTTP. Impl. Client. AbstractHttpClient. Execute (AbstractHttpClient. Java: 555)
The at org. Apache. HTTP. Impl. Client. AbstractHttpClient. Execute (AbstractHttpClient. Java: 487)
The at org. Apache. HTTP. Impl. Client. AbstractHttpClient. Execute (AbstractHttpClient. Java: 465)
The at org. Alexd. Jsonrpc. JSONRPCHttpClient. DoJSONRequest (JSONRPCHttpClient. Java: 100)
. 4 more
Under Caused by: java.net.ConnectException: failed to connect to/10.21.23.135 (port 8545) : connect failed: ECONNREFUSED (Connection refused)
The at libcore. IO. IoBridge. Connect (IoBridge. Java: 114)
At java.net.PlainSocketImpl.connect PlainSocketImpl. Java: (192)
At java.net.PlainSocketImpl.connect PlainSocketImpl. Java: (459)
At java.net.Socket.connect (843) Socket. Java:
The at org. Apache. HTTP. Conn. Scheme. PlainSocketFactory. ConnectSocket (PlainSocketFactory. Java: 119)
The at org. Apache. HTTP. Impl. Conn. DefaultClientConnectionOperator. OpenConnection (DefaultClientConnectionOperator. Java: 144)
. 11 more
Under Caused by: libcore. IO. ErrnoException: connect failed: ECONNREFUSED (Connection refused)
The at libcore. IO. Posix. Connect (Native Method)
The at libcore. IO. BlockGuardOs. Connect (BlockGuardOs. Java: 85)
The at libcore. IO. IoBridge. ConnectErrno (IoBridge. Java: 127)
The at libcore. IO. IoBridge. Connect (IoBridge. Java: 112)
. 16 more

What a great god can help see

CodePudding user response:

String st=client. CallString (" web3_clientVersion ", map); Error message shows you here cannot be converted to a stringnullnullnullnullnullnullnullnullnullnullnull
  • Related