2014-04-19 137 views
0

我是新来的android和问题头说,我不能点击按钮开始新的活动。我得到的错误是here。我正在制作应用程序,用户需要注册才能使用应用程序的功能。Android:无法启动点击按钮

下面是按钮的单击事件的片段:

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(); 
    } 
?> 

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

谢谢。

+0

而不是getApplicationContext()使用YourActivityName.this – jyomin

+0

也试过,还是得到相同的错误.. –

+0

这段代码很好..看起来像错误是从数据库..你可以发布其他相关的代码? –

回答

0

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

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

-1

试试这个:

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

不,同样的错误.. –

+0

发布您的错误日志 – Lokesh

+0

检查它,我已经在 –