首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NanoHTTPD不工作

NanoHTTPD不工作
EN

Stack Overflow用户
提问于 2013-07-17 13:38:31
回答 1查看 1.4K关注 0票数 0

大家好,我正在用NanoHttpd为安卓创建一个web服务器,当我运行它的时候,.It说活动已经停止了,请帮助我该怎么做。这是我正在使用的代码。代码如下:

代码语言:javascript
复制
    package dolphin.developers.com;

import java.io.IOException;
import java.util.Map;

public class  MyHTTPD  extends NanoHTTPD {

    /**
    * Constructs an HTTP server on given port.
    */
   public MyHTTPD()throws IOException {
       super(8080);
   }


@Override
   public Response serve( String uri, Method method,
           Map<String, String> header, Map<String, String> parms,
           Map<String, String> files )
   {
       System.out.println( method + " '222" + uri + "' " );
       String msg = "<html><body><h1>Hello server</h1>\n";
       if ( parms.get("username") == null )
           msg +=
               "<form action='?' method='get'>\n" +
               "  <p>Your name: <input type='text' name='username'></p>\n" +
               "</form>\n";
       else
           msg += "<p>Hello, " + parms.get("username") + "!</p>";

       msg += "</body></html>\n";
       return new NanoHTTPD.Response(msg );
   }


   public static void main( String[] args )
   {
       try
       {
           new MyHTTPD();
       }
       catch( IOException ioe )
       {
           System.err.println( "Couldn't start server:\n" + ioe );
           System.exit( -1 );
       }
       System.out.println( "Listening on port 8080. Hit Enter to stop.\n" );
       try { System.in.read(); } catch( Throwable t ) {
           System.out.println("read error");
       };
   }

}

LogCat:

代码语言:javascript
复制
07-14 22:35:26.394: E/AndroidRuntime(581): FATAL EXCEPTION: main
07-14 22:35:26.394: E/AndroidRuntime(581): android.content.ActivityNotFoundException: Unable to find explicit activity class {dolphin.devlopers.com/dolphin.developers.com.MyHTTPD}; have you declared this activity in your AndroidManifest.xml?
07-14 22:35:26.394: E/AndroidRuntime(581):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
07-14 22:35:26.394: E/AndroidRuntime(581):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-14 22:35:26.394: E/AndroidRuntime(581):  at android.app.Activity.startActivityForResult(Activity.java:2817)
07-14 22:35:26.394: E/AndroidRuntime(581):  at android.app.Activity.startActivity(Activity.java:2923)
07-14 22:35:26.394: E/AndroidRuntime(581):  at dolphin.developers.com.facebook1$DownloadFileFromURL.onPostExecute(facebook1.java:167)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-17 13:54:41

查看您的AndroidManifest.xml,并确保您的主活动已注册(在本例中为MyHTTPD)。这是一个非常基本的清单文件,看一下标签。我把你的作品放进你的班级。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.epstest"
    android:versionCode="1"
    android:versionName="1.0" >
    ....
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

--------------------------------------------------------------------------------------------------

代码语言:javascript
复制
        <activity
            android:name="dolphin.developers.com.MyHTTPD"
            android:label="@string/title"
            android:configChanges="orientation" >
        </activity>

--------------------------------------------------------------------------------------------------

代码语言:javascript
复制
    </application>

</manifest>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17691913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档