java - Error with the bundle on a new thread -
i have problem. created tcp client executes in new thread connection server. unfortunately, program shuts down. in logcat following message:
"fatal exception: thread-14635 process: com.example.sebastian.ravia, pid: 8648 java.lang.nullpointerexception: attempt invoke virtual method 'android.os.bundle android.content.intent.getextras () on null object reference @ com.example.sebastian.ravia.clientthread.run (tcpclient.java:36) @ java.lang.thread.run (thread.java:818)
the problem in: "bundle przekazanedane". bundle download text string of edittext previous activity.
here's code:
public class tcpclient extends activity { //private socket socketin; //private socket socketout; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.client_activity); new thread(new clientthread()).start(); } } class clientthread extends tcpclient implements runnable { private boolean arun = false; private string ahost; private string asocketin; private string asocketout; public void run() { bundle przekazanedane = getintent().getextras(); if(przekazanedane != null) { ahost = przekazanedane.getstring("addressip"); asocketin = przekazanedane.getstring("socketin"); asocketout = przekazanedane.getstring("socketout"); } int asocketinint; int asocketoutint; arun = true; asocketinint = integer.parseint(asocketin); asocketoutint = integer.parseint(asocketout); try { inetaddress serweraddress = inetaddress.getbyname(ahost); socket socket = new socket(serweraddress, asocketinint); printwriter out = new printwriter(socket.getoutputstream(),true); bufferedreader in = new bufferedreader(new inputstreamreader(socket.getinputstream())); } catch (exception e) { e.printstacktrace(); } } }
Comments
Post a Comment