Sunday, 15 January 2012

android - Fatal error while creating UDP Server -



android - Fatal error while creating UDP Server -

i using code gives errors, unable trace. help appreciated. here code:

package com.example.test; import java.net.datagrampacket; import java.net.datagramsocket; import android.app.activity; import android.os.bundle; import android.util.log; import android.view.menu; import android.widget.textview; public class mainactivity extends activity { textview display; private mydatagramreceiver mydatagramreceiver = null; protected void onresume() { mydatagramreceiver = new mydatagramreceiver(); mydatagramreceiver.start(); } protected void onpause() { // mydatagramreceiver.kill(); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); display=(textview) findviewbyid(r.id.textview1); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); homecoming true; } private class mydatagramreceiver extends thread { private boolean bkeeprunning = true; private string lastmessage = ""; public void run() { string message; byte[] lmessage = new byte[100]; seek { datagramsocket socket = new datagramsocket(2690); log.v("run", "socket created"); while(bkeeprunning) { datagrampacket packet = new datagrampacket(lmessage, lmessage.length); socket.receive(packet); message = new string(lmessage, 0, packet.getlength()); lastmessage = message; runonuithread(updatetextmessage); log.v("receiving", "packet recvd"); } if (socket != null) { socket.close(); log.v("soc", "socket closed"); } } grab (throwable e) { e.printstacktrace(); } } } public void kill() { bkeeprunning = false; } public string getlastmessage() { homecoming lastmessage; } private runnable updatetextmessage = new runnable() { public void run() { if (mydatagramreceiver == null) return; display.settext(mydatagramreceiver.getlastmessage()); } }; } }

following errors:

11-14 03:04:06.240: e/androidruntime(881): fatal exception: main 11-14 03:04:06.240: e/androidruntime(881): process: com.example.test, pid: 881 11-14 03:04:06.240: e/androidruntime(881): java.lang.runtimeexception: unable resume activity {com.example.test/com.example.test.mainactivity}: android.util.supernotcalledexception: activity {com.example.test/com.example.test.mainactivity} did not phone call through super.onresume() 11-14 03:04:06.240: e/androidruntime(881): java.lang.runtimeexception: unable resume activity {com.example.test/com.example.test.mainactivity}: android.util.supernotcalledexception: activity {com.example.test/com.example.test.mainactivity} did not phone call through super.onresume() 11-14 03:04:06.240: e/androidruntime(881): caused by: android.util.supernotcalledexception: activity {com.example.test/com.example.test.mainactivity} did not phone call through super.onresume()

thanks

add missing super-calls in code:

protected void onresume() { super.onresume(); mydatagramreceiver = new mydatagramreceiver(); mydatagramreceiver.start(); } protected void onpause() { super.onpause(); // mydatagramreceiver.kill(); }

android

No comments:

Post a Comment