0

大家好,我正在使用 NanoHttpd 为 android 创建一个 Web 服务器,当我运行它时。它说 Activity 已停止工作,请帮助我该怎么办。这是我正在使用的代码。代码如下:

    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");
       };
   }

}

日志猫:

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)
4

1 回答 1

0

查看您的 AndroidManifest.xml 并确保您的主要活动已注册(在您的情况下为 MyHTTPD)。这是一个非常基本的清单文件,看看标签。我把你的课作为一个条目。

<?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" >

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

        <activity
            android:name="dolphin.developers.com.MyHTTPD"
            android:label="@string/title"
            android:configChanges="orientation" >
        </activity>

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

    </application>

</manifest>
于 2013-07-17T05:54:41.177 回答