簡體   English   中英

即使存在明確的活動類別也無法找到

[英]Unable to find explicit activity class even though it exists

我不明白為什么會收到此錯誤。 看來清單中的所有設置都正確設置,所以我不理解logcat錯誤:

12-29 17:22:50.111: E/AndroidRuntime(24103): FATAL EXCEPTION: main
12-29 17:22:50.111: E/AndroidRuntime(24103): java.lang.IllegalStateException: Could not execute method of the activity
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.view.View$1.onClick(View.java:3633)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.view.View.performClick(View.java:4240)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.view.View$PerformClick.run(View.java:17721)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.os.Handler.handleCallback(Handler.java:730)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.os.Handler.dispatchMessage(Handler.java:92)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.os.Looper.loop(Looper.java:137)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.app.ActivityThread.main(ActivityThread.java:5103)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at java.lang.reflect.Method.invokeNative(Native Method)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at java.lang.reflect.Method.invoke(Method.java:525)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at dalvik.system.NativeStart.main(Native Method)
12-29 17:22:50.111: E/AndroidRuntime(24103): Caused by: java.lang.reflect.InvocationTargetException
12-29 17:22:50.111: E/AndroidRuntime(24103):    at java.lang.reflect.Method.invokeNative(Native Method)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at java.lang.reflect.Method.invoke(Method.java:525)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.view.View$1.onClick(View.java:3628)
12-29 17:22:50.111: E/AndroidRuntime(24103):    ... 11 more
12-29 17:22:50.111: E/AndroidRuntime(24103): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.cm.pkg/com.cm.pkg.RequestTask$Registration}; have you declared this activity in your AndroidManifest.xml?
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.app.Activity.startActivityForResult(Activity.java:3390)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.app.Activity.startActivityForResult(Activity.java:3351)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.app.Activity.startActivity(Activity.java:3587)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at android.app.Activity.startActivity(Activity.java:3555)
12-29 17:22:50.111: E/AndroidRuntime(24103):    at com.cm.pkg.AndroidLogin.RegisterButton(AndroidLogin.java:147)
12-29 17:22:50.111: E/AndroidRuntime(24103):    ... 14 more

注冊.java

package com.cm.pkg;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.cm.pkg.R;

import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;


class RequestTask extends AsyncTask<String, String, String>{
      String responseString = null;


    @Override
    protected String doInBackground(String... uri) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response;

        try {
            response = httpclient.execute(new HttpGet(uri[0]));
            StatusLine statusLine = response.getStatusLine();
            if(statusLine.getStatusCode() == HttpStatus.SC_OK){
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                out.close();
                String responseString = null;
                responseString = out.toString();
                Log.d("check response", responseString);


            } else{
                //Closes the connection.
                response.getEntity().getContent().close();
                throw new IOException(statusLine.getReasonPhrase());
            }
        } catch (ClientProtocolException e) {
            //TODO Handle problems..
        } catch (IOException e) {
            //TODO Handle problems..
        }
        return responseString;
    }


    protected void onPostExecute(String result) {
        super.onPostExecute(result);


    }







String result = null;

public class Registration extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
          TextView detail = (TextView)findViewById(R.id.resulttext);
            detail.setText(result);
    }


    public void SubmitRegistration(View view) {




           // assign text in fields to string values
           EditText first = (EditText)findViewById(R.id.first);
           String first2 = first.getText().toString();

           EditText last = (EditText)findViewById(R.id.last);
           String last2 = last.getText().toString();

           EditText display = (EditText)findViewById(R.id.display);
           String display2 = display.getText().toString();
           //calculates the number of characters in the display field
           int length2 = display2.length();


           EditText email = (EditText)findViewById(R.id.email);
           String email2 = email.getText().toString();


           EditText password = (EditText)findViewById(R.id.password);
           String password2 = password.getText().toString();


           EditText vpassword = (EditText)findViewById(R.id.vpassword);
           String vpassword2 = vpassword.getText().toString();
           //calculates the number of characters in the password field
           int length = vpassword2.length();






    // verifying the following in order:  Passwords match? A Password field is empty?  
                                        //Password and Display Name less than 6 characters long? Email contains an @ sign and a period?   
           if(!vpassword2.equals(password2))
           {
               Toast.makeText(getApplicationContext(), "Passwords do not match!", Toast.LENGTH_SHORT).show(); 


           }
           else if (password2.isEmpty() || vpassword2.isEmpty()){

               Toast.makeText(getApplicationContext(), "Password field is empty", Toast.LENGTH_SHORT).show(); 
           }
           else if (length < 6 || length2 < 6 ) {

               Toast.makeText(getApplicationContext(), "Password and Display Name must be at least 6 characters long", Toast.LENGTH_LONG).show(); 

           }

           else if (!email2.contains("@") || !email2.contains(".")){

               Toast.makeText(getApplicationContext(), "Must enter valid email address.", Toast.LENGTH_SHORT).show(); 

           }

           else {


               //send php with all the data to server for validation and insertion into table
               new RequestTask().execute("http://www.somewebsite.com/android/registercheck.php?first=" + first2 + "&last=" + last2 + "&dispname=" + display2 + "&email=" + email2 + "&password=" + password2 );                       



           }
   }







}

}

AndroidLogin.java

package com.cm.pkg;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import com.cm.pkg.RequestTask.Registration;
import com.cm.pkg.R;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;







public class AndroidLogin extends Activity implements OnClickListener {


    Button ok,back,exit;
    TextView result;




    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
       setContentView(R.layout.main);



        // Login button clicked
        ok = (Button)findViewById(R.id.btn_login);
        ok.setOnClickListener(this);


        result = (TextView)findViewById(R.id.tbl_result);



    }









    public void postLoginData() {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();


        // login.php returns true if username and password match in db 
        HttpPost httppost = new HttpPost("http://www.somewebsite.com/android/login.php");

        try {




            // Add user name and password
            EditText uname = (EditText)findViewById(R.id.txt_username);
            String username = uname.getText().toString();



            EditText pword = (EditText)findViewById(R.id.txt_password);
            String password = pword.getText().toString();

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("username", username));
            nameValuePairs.add(new BasicNameValuePair("password", password));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            Log.w("SENCIDE", "Execute HTTP Post Request");
            HttpResponse response = httpclient.execute(httppost);

            String str = inputStreamToString(response.getEntity().getContent()).toString();
            Log.w("SENCIDE", str);

            if(str.toString().equalsIgnoreCase("true"))
            {
                Log.w("SENCIDE", "TRUE");
                result.setText("Login Successful! Please Wait...");   
            }else
            {
                Log.w("SENCIDE", "FALSE");
                result.setText(str);                
            }

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } 

    private StringBuilder inputStreamToString(InputStream is) {
        String line = "";
        StringBuilder total = new StringBuilder();
        // Wrap a BufferedReader around the InputStream
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        // Read response until the end
        try {
            while ((line = rd.readLine()) != null) { 
                total.append(line); 
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Return full string
        return total;
    }


    public void RegisterButton(View view) {

         Intent intent2 = new Intent(this, Registration.class);
        startActivity(intent2);

    }




    @Override
    public void onClick(View view) {
                postLoginData();




                // turns the text in the textview "Tbl_result" into a text string called "tblresult"
                TextView tblresult = (TextView) findViewById(R.id.tbl_result);




        // If "tblresult" text string matches the string "Login Successful! Please Wait..." exactly, it will switch to next activity
                if (tblresult.getText().toString().equals("Login Successful! Please Wait...")) {
                      Intent intent = new Intent(this, Homepage.class);
                      EditText uname2 = (EditText)findViewById(R.id.txt_username);
                      String username2 = uname2.getText().toString();
                      intent.putExtra("username2", username2);
                      startActivity(intent);
                   }    






    }



}

我的清單:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.cm.pkg"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/icon"
        android:label="ChallengeMe" >
        <activity
            android:name="com.cm.pkg.AndroidLogin"
            android:label="Login Please" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.cm.pkg.Registration"
            android:label="Registration" >
        </activity>
        <activity
            android:name="com.cm.pkg.Homepage"
            android:label="Welcome Home" >
        </activity>
    </application>

</manifest>

這是我的設置,我可以在其中看到請求任務以及注冊信息,這是怎么回事!?

在此處輸入圖片說明

我嘗試過重新啟動Eclipse,進行重建,但我不知道在這里還有什么嘗試。

我在相同的com.cm.pkg中創建了一個名為“ RequestTask.java”的類,並從Registration.java類中進行了剪切/粘貼。 這似乎可以解決所有問題。 謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM