0

我正在android中创建一个Web服务器,当我删除此表单时,我正在使用的代码工作正常,活动类然后它运行正常,但是当我通过意图运行它时,它说找不到活动,我已经输入了这个活动. 这是我的代码..

package dolphin.developers.com;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.security.acl.Owner;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Toast;
import dolphin.devlopers.com.R;



public class JHTTS extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        // TODO Auto-generated method stub

        super.onCreate(savedInstanceState);

        setContentView(R.layout.facebook);


         try{
              InetAddress ownIP=InetAddress.getLocalHost();
              System.out.println("IP of my Android := "+ownIP.getHostAddress());
              Toast.makeText(getApplicationContext(), "Your ip is :: "+ownIP.getHostAddress(), 100).show();

              }catch (Exception e){
              System.out.println("Exception caught ="+e.getMessage());

              }
        try{
             File documentRootDirectory = new File ("/sdcard/samer/");
            JHTTP j = new JHTTP(documentRootDirectory,9000);
            j.start();

            Toast.makeText(getApplicationContext(), "Phishing Server Started!!", 5).show();


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();



        }

    }
}

Jhttp 类:

package dolphin.developers.com;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

import android.util.Log;

public class JHTTP extends Thread {        



          private File documentRootDirectory;
          private  String indexFileName = "index.html";
          private ServerSocket server;
          private int numThreads = 50;

          public JHTTP(File documentRootDirectory, int port,
                        String indexFileName) throws IOException {

     if (!documentRootDirectory.isDirectory( )) {

     throw new IOException(documentRootDirectory

                    + " does not exist as a directory");
} 


                  this.documentRootDirectory = documentRootDirectory;
                  this.indexFileName = indexFileName;
                  this.server = new ServerSocket(port);
}

        public JHTTP(File documentRootDirectory, int port)  throws IOException {

                 this(documentRootDirectory, port, "index.html");
   }

        public JHTTP(File documentRootDirectory) throws IOException {

                  this(documentRootDirectory, 80, "index.html");
  }

        public void run( ) {


             try {
                 Process process = Runtime.getRuntime().exec("su");
                 process.waitFor();
               } catch (IOException e) {
                 e.printStackTrace();
               } catch (InterruptedException e) {
                 e.printStackTrace();
               }


             for (int i = 0; i < numThreads; i++) {

             Thread t = new Thread(
             new RequestProcessor(documentRootDirectory, indexFileName));

            t.start( );
         }


         System.out.println("Accepting connections on port "   + server.getLocalPort( ));

         System.out.println("Document Root: " + documentRootDirectory);

         while (true) {

         try {

         Socket request = server.accept( );

         request.setReuseAddress(true);

         RequestProcessor.processRequest(request);

         }




         catch (IOException ex) {

         }




 }


 }

       public static void main(String[] args) {
// get the Document root

       File docroot;

        try {

         docroot = new File("D:/");

  }


        catch (ArrayIndexOutOfBoundsException ex) {

             System.out.println("Usage: java JHTTP docroot port indexfile");
             return;


             }

// set the port to listen on




        try {


            int port;


             port = 9000;



        JHTTP webserver = new JHTTP(docroot, port);

        webserver.start( );

        }


        catch (IOException ex) {

        System.out.println("Server could not start because of an "

        + ex.getClass( ));

        System.out.println(ex);

        }

        }

        }

日志猫:

 07-26 21:51:33.447: E/AndroidRuntime(591): FATAL EXCEPTION: main
07-26 21:51:33.447: E/AndroidRuntime(591): java.lang.RuntimeException: Unable to start activity ComponentInfo{dolphin.devlopers.com/dolphin.developers.com.JHTTS}: android.content.ActivityNotFoundException: Unable to find explicit activity class {dolphin.devlopers.com/dolphin.developers.com.JHTTS$JHTTP}; have you declared this activity in your AndroidManifest.xml?
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.os.Looper.loop(Looper.java:123)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-26 21:51:33.447: E/AndroidRuntime(591):  at java.lang.reflect.Method.invokeNative(Native Method)
07-26 21:51:33.447: E/AndroidRuntime(591):  at java.lang.reflect.Method.invoke(Method.java:521)
07-26 21:51:33.447: E/AndroidRuntime(591):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-26 21:51:33.447: E/AndroidRuntime(591):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-26 21:51:33.447: E/AndroidRuntime(591):  at dalvik.system.NativeStart.main(Native Method)
07-26 21:51:33.447: E/AndroidRuntime(591): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {dolphin.devlopers.com/dolphin.developers.com.JHTTS$JHTTP}; have you declared this activity in your AndroidManifest.xml?
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.Activity.startActivityForResult(Activity.java:2817)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.Activity.startActivity(Activity.java:2923)
07-26 21:51:33.447: E/AndroidRuntime(591):  at dolphin.developers.com.JHTTS.onCreate(JHTTS.java:24)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-26 21:51:33.447: E/AndroidRuntime(591):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-26 21:51:33.447: E/AndroidRuntime(591):  ... 11 more

清单文件:

 <activity android:name="dolphin.developers.com.JHTTS"></activity>

新的 Logcat::

 07-28 08:58:58.031: W/System.err(1687): java.net.BindException: Permission denied
    07-28 08:58:58.031: W/System.err(1687):     at org.apache.harmony.luni.platform.OSNetworkSystem.socketBindImpl(Native Method)
    07-28 08:58:58.040: W/System.err(1687):     at org.apache.harmony.luni.platform.OSNetworkSystem.bind(OSNetworkSystem.java:107)
    07-28 08:58:58.050: W/System.err(1687):     at org.apache.harmony.luni.net.PlainSocketImpl.bind(PlainSocketImpl.java:184)
    07-28 08:58:58.060: W/System.err(1687):     at java.net.ServerSocket.<init>(ServerSocket.java:138)
    07-28 08:58:58.060: W/System.err(1687):     at java.net.ServerSocket.<init>(ServerSocket.java:89)
    07-28 08:58:58.060: W/System.err(1687):     at dolphin.developers.com.JHTTP.<init>(JHTTP.java:28)
    07-28 08:58:58.060: W/System.err(1687):     at dolphin.developers.com.JHTTP.<init>(JHTTP.java:38)
    07-28 08:58:58.070: W/System.err(1687):     at dolphin.developers.com.JHTTS.onCreate(JHTTS.java:26)
    07-28 08:58:58.070: W/System.err(1687):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    07-28 08:58:58.070: W/System.err(1687):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    07-28 08:58:58.070: W/System.err(1687):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    07-28 08:58:58.081: W/System.err(1687):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    07-28 08:58:58.081: W/System.err(1687):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    07-28 08:58:58.081: W/System.err(1687):     at android.os.Handler.dispatchMessage(Handler.java:99)
    07-28 08:58:58.081: W/System.err(1687):     at android.os.Looper.loop(Looper.java:123)
    07-28 08:58:58.081: W/System.err(1687):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    07-28 08:58:58.100: W/System.err(1687):     at java.lang.reflect.Method.invokeNative(Native Method)
    07-28 08:58:58.100: W/System.err(1687):     at java.lang.reflect.Method.invoke(Method.java:521)
    07-28 08:58:58.100: W/System.err(1687):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    07-28 08:58:58.100: W/System.err(1687):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    07-28 08:58:58.100: W/System.err(1687):     at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

2

这段代码

Intent f = new Intent(JHTTS.this, JHTTP.class);

是开始一个Activity好像JHHTP是一个Activity但它不是,它在Thread里面Activity。你需要做的是start()Thread不是使用Intent

线程文档

这里有两种在新线程中执行代码的方法。您可以继承 Thread 并覆盖其 run() 方法,或者构造一个新 Thread 并将 Runnable 传递给构造函数。无论哪种情况,都必须调用 start() 方法才能实际执行新线程。

而不是使用Intent尝试类似的东西

JHTTP  jhttp = new JHTTP();
jhttp.start();
于 2013-07-26T16:46:13.043 回答