java - Nanohttpd server in Android -


i developing android app uses nanohttpd create web server , when run it says activity has stopped code please me appriciated.here goes code:

  package dolphin.developers.com;   import java.io.ioexception; import java.io.inputstream; import java.util.map;  import android.content.context; import android.os.environment;   public class myhttpd extends nanohttpd{  private context ctx;   public myhttpd(context ctx) throws ioexception { super(8080);    this.ctx = ctx;  }   @override public response serve( string uri, method method,          map<string, string> header, map<string, string> parms,        map<string, string> files )        {         string html = null;         inputstream = null;         try {             = ctx.getassets().open(environment.getexternalstoragedirectory()+"/index.htm");         } catch (ioexception e1) {             // todo auto-generated catch block             e1.printstacktrace();         }         byte[] b;         try {             b = new byte[is.available()];             is.read(b);             html = new string(b);         } catch (ioexception e) { // todo auto-generated catch block             e.printstacktrace();         }            return new nanohttpd.response(html);        } } 

logcat:

07-17 12:06:22.538: e/androidruntime(1137): fatal exception: main 07-17 12:06:22.538: e/androidruntime(1137): java.lang.runtimeexception: unable instantiate activity componentinfo{dolphin.devlopers.com/dolphin.developers.com.myhttpd}: java.lang.classcastexception: dolphin.developers.com.myhttpd cannot cast android.app.activity 07-17 12:06:22.538: e/androidruntime(1137):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2106) 07-17 12:06:22.538: e/androidruntime(1137):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 07-17 12:06:22.538: e/androidruntime(1137):     @ android.app.activitythread.access$600(activitythread.java:141) 07-17 12:06:22.538: e/androidruntime(1137):     @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 07-17 12:06:22.538: e/androidruntime(1137):     @ android.os.handler.dispatchmessage(handler.java:99) 07-17 12:06:22.538: e/androidruntime(1137):     @ android.os.looper.loop(looper.java:137) 07-17 12:06:22.538: e/androidruntime(1137):     @ android.app.activitythread.main(activitythread.java:5039) 07-17 12:06:22.538: e/androidruntime(1137):     @ java.lang.reflect.method.invokenative(native method) 07-17 12:06:22.538: e/androidruntime(1137):     @ java.lang.reflect.method.invoke(method.java:511) 07-17 12:06:22.538: e/androidruntime(1137):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 07-17 12:06:22.538: e/androidruntime(1137):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 07-17 12:06:22.538: e/androidruntime(1137):     @ dalvik.system.nativestart.main(native method) 07-17 12:06:22.538: e/androidruntime(1137): caused by: java.lang.classcastexception: dolphin.developers.com.myhttpd cannot cast android.app.activity 07-17 12:06:22.538: e/androidruntime(1137):     @ android.app.instrumentation.newactivity(instrumentation.java:1054) 07-17 12:06:22.538: e/androidruntime(1137):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2097) 07-17 12:06:22.538: e/androidruntime(1137):     ... 11 more 

you can declare classes extend android's "activity" in manifest activities. try creating one, , in activity lifecycle (oncreate / ondestroy or onstart / onstop) try start , stop nanohttpd server.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -