即使存在,也无法找到显式活动类

时间:2013-12-30 01:54:04

标签: java android eclipse

我不明白为什么我会收到此错误。看起来清单中的所有内容都已正确设置,因此我无法理解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

Registration.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>

这是我的设置,我可以在那里看到请求任务以及注册,这里发生了什么!?

enter image description here

我已经尝试重启eclipse,重建,我不知道还有什么可以尝试。

1 个答案:

答案 0 :(得分:0)

我在同一个com.cm.pkg中创建了一个名为“RequestTask.java”的类,并从Registration.java类中剪切/粘贴。这似乎解决了一切。谢谢。