Android:单击按钮无法启动活动

时间:2014-04-19 10:49:40

标签: android

我是android的新手,问题负责人说,我无法点击按钮开始新的活动。我得到的错误是here。我正在制作用户需要注册的应用程序,以便使用该应用程序的功能。

这是按钮点击事件的片段:

package com.example.entrepreneurexpress.investors;

import java.net.URLEncoder;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.entrepreneurexpress.R;
import com.example.entrepreneurexpress.libraries.GetPasswordFromServer;

public class InvestorsLogin extends Activity{

    EditText PASSWORD, EMAILID;
    String extracted_email, extracted_password, recieved_password,final_request;
    ProgressDialog pDialog;

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.investor_login);

        ActionBar aBar = getActionBar();
        aBar.setDisplayHomeAsUpEnabled(true);

        Button btnInvLogClear = (Button) findViewById(R.id.btnInvClear);
        Button btnInvLogin = (Button) findViewById(R.id.btnInvLogin);
        Button btnInvRegister = (Button) findViewById(R.id.btnInvRegister);

        EMAILID = (EditText) findViewById(R.id.txtInvEmailAddress);
        PASSWORD = (EditText) findViewById(R.id.txtInvPassword);

        btnInvLogClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (EMAILID.length() >= 1) {
                    EMAILID.setText("");
                }
                if (PASSWORD.length() >= 1) {
                    PASSWORD.setText("");
                }
            }
        });

        btnInvRegister.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intInvRegister = new Intent(InvestorsLogin.this, InvestorsRegister.class);
                startActivity(intInvRegister);
            }
        });

        btnInvLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                extracted_email = EMAILID.getText().toString();
                extracted_password = PASSWORD.getText().toString();

                if(EMAILID.length() < 1 || PASSWORD.length() < 1) {
                    Toast.makeText(getApplicationContext(), "Please Fill In All The Details", Toast.LENGTH_LONG).show();
                } else {
                    new LoginInvestorTask().execute(extracted_email);
                }
            }
        });
    }

    class LoginInvestorTask extends AsyncTask<String, Void, String> {

        @Override
        protected void onPreExecute(){
            pDialog = new ProgressDialog(InvestorsLogin.this);
            pDialog.setTitle("Processing...");
            pDialog.setMessage("Checking Your Credentials...");
            pDialog.setCancelable(true);
            pDialog.setIndeterminate(true);
            pDialog.show();
        }

        @SuppressWarnings("deprecation")
        @Override
        protected String doInBackground(String... params) {
            final_request="http://mehul.wink.ws/selectEntrepreneurToLogin.php?emailid="+URLEncoder.encode(extracted_email);
            GetPasswordFromServer test=new GetPasswordFromServer();         
            try {
                return test.getServerData(final_request);
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

        @SuppressLint("ShowToast")
        @Override
        protected void onPostExecute(String result) {
            try {
                recieved_password=result;
                if(pDialog != null) {
                    pDialog.dismiss();
                }

                if(recieved_password.equals(extracted_password)){
                    Toast.makeText(getApplicationContext(), "Success !", Toast.LENGTH_LONG).show();
                    /*Intent welcomeInvestor = new Intent(getApplicationContext(), WelcomeInvestor.class);
                    welcomeInvestor.putExtra("email", extracted_email);
                    startActivity(welcomeInvestor);*/
                }
            } catch(Exception e) {
                Toast.makeText(getApplicationContext(), "Invalid Credentials", Toast.LENGTH_LONG).show();
            }
        }
    }
}

这是我得到的错误:

    EntrepreneurExpress [Android Application]   
EntrepreneurExpress [Android Application]   
    DalvikVM [localhost:8600]   
        Thread [<1> main] (Suspended (exception RuntimeException))  
            <VM does not provide monitor information>   
            ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2351    
            ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2403 
            ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 165    
            ActivityThread$H.handleMessage(Message) line: 1373  
            ActivityThread$H(Handler).dispatchMessage(Message) line: 107    
            Looper.loop() line: 194 
            ActivityThread.main(String[]) line: 5391    
            Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
            Method.invoke(Object, Object...) line: 525  
            ZygoteInit$MethodAndArgsCaller.run() line: 833  
            ZygoteInit.main(String[]) line: 600 
            NativeStart.main(String[]) line: not available [native method]  
        Thread [<10> Binder_2] (Running)    
        Thread [<9> Binder_1] (Running) 
        Thread [<11> Binder_3] (Running)

这是我用来插入mysql数据库的php代码:

<?php

$nm = $_GET['nm'];
$email = $_GET['email'];
$password = $_GET['pass'];

$con = new PDO("mysql:host=hostname; dbname=databasename", "username", "password");
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    try {
        $query = $con->prepare("INSERT INTO Investors (invName, invEmailId, invPassword)
                                VALUES(:name, :email, :passWord)");
        $query->bindParam(':name', $nm);
        $query->bindParam(':email', $email);
        $query->bindParam(':passWord', $password);
        $query->execute();
    }catch(PDOException $ex) {
        echo "Some Exception Occured: <br />" . $ex->getMessage();
    }
?>

我不明白我哪里出错了。请帮助我。

感谢。

2 个答案:

答案 0 :(得分:0)

我现在正在回答我自己的问题。我忘了检查布局xml文件,这导致了未打开所需活动的错误,这是我自己的错误。

我在java文件中输入了错误。我点击了按钮时使用了错误的ID。现在一切都解决了。

答案 1 :(得分:-1)

试试这个:

btnInvRegister.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intInvRegister = new Intent(CurrentActivity.this, InvestorsRegister.class);
        startActivity(intInvRegister);
    }
});