Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android中的Nanohttpd不提供文件_Java_Android_Webserver_Nanohttpd - Fatal编程技术网

Java android中的Nanohttpd不提供文件

Java android中的Nanohttpd不提供文件,java,android,webserver,nanohttpd,Java,Android,Webserver,Nanohttpd,我正在开发一个android应用程序,它使用nanohttpd创建一个Web服务器。我的代码没有给我任何错误,但服务器没有运行,因为当我转到xx.xxx.xxx.xxx:8765/index.htm时,它没有给我任何结果。这是我的代码: 请帮忙 package dolphin.developers.com; import java.io.File; import java.io.IOException; import java.util.Properties; import dolphin

我正在开发一个android应用程序,它使用nanohttpd创建一个Web服务器。我的代码没有给我任何错误,但服务器没有运行,因为当我转到xx.xxx.xxx.xxx:8765/index.htm时,它没有给我任何结果。这是我的代码: 请帮忙

package dolphin.developers.com;

import java.io.File;
import java.io.IOException;
 import java.util.Properties;

import dolphin.devlopers.com.R;

import android.app.Activity;
 import android.os.Bundle;
import android.os.Environment;

     public class AlertDialogActivity extends Activity {
     private static final int PORT = 8765; 
     private MyHTTPD server;

  @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
 }

 @Override
  protected void onResume() {
    super.onResume();


  try {
   server = new MyHTTPD();
   } catch (IOException e) {

        e.printStackTrace();
}
}



    @Override

    protected void onPause() {

        super.onPause();

        if (server != null)
      server.stop();

    }

    public class MyHTTPD extends NanoHTTPD {

         public MyHTTPD() throws IOException {

             super(PORT, null);

         }

         public Response serve( String uri, String method, Properties header, Properties parms, Properties files ) {
                File rootsd = Environment.getExternalStorageDirectory();
                File path = new File(rootsd.getAbsolutePath() + "/samer");
                Response r = super.serveFile("/index.htm", header, path, true);
                return r;
}
}
}
看起来像是一个简单的修复——在onResume()中,您创建了服务器,但仍然需要对其调用“start()”