1 Replies - 3979 Views - Last Post: 30 June 2012 - 09:28 PM

#1 polens  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 155
  • Joined: 09-November 09

not going to next activity help!

Posted 28 June 2012 - 06:15 AM

i have this error
06-28 21:08:36.339: E/AndroidRuntime(2401): FATAL EXCEPTION: main
06-28 21:08:36.339: E/AndroidRuntime(2401): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hypermart.namespace/com.hypermart.namespace.RegisterActivity}: java.lang.NullPointerException
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.os.Looper.loop(Looper.java:137)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at java.lang.reflect.Method.invokeNative(Native Method)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at java.lang.reflect.Method.invoke(Method.java:511)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at dalvik.system.NativeStart.main(Native Method)
06-28 21:08:36.339: E/AndroidRuntime(2401): Caused by: java.lang.NullPointerException
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at com.hypermart.namespace.RegisterActivity.onCreate(RegisterActivity.java:28)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.app.Activity.performCreate(Activity.java:4465)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-28 21:08:36.339: E/AndroidRuntime(2401): 	... 11 more


basically the application stops in the emulator when the button is click...

here is the code
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_form);
        
        btnLinkToRegister=(Button)findViewById(R.id.btnRegister);
        b = (Button)findViewById(R.id.btnLogin);  
        et = (EditText)findViewById(R.id.loginUsername);
        pass= (EditText)findViewById(R.id.loginPassword);
        tv = (TextView)findViewById(R.id.login_error);
      
        
        
        b.setonclickListener(new onclickListener() {
			
			public void onclick(View v) {
				dialog = ProgressDialog.show(MobileHyperMartActivity.this, "", 
                        "Validating user...", true);
				 new Thread(new Runnable() {
					    public void run() {

							try{			
								 
								httpclient=new DefaultHttpClient();
								httppost= new HttpPost("http://10.0.2.2/Webservice/Connections.php"); // make sure the url is correct.
								//add your data
								
								nameValuePairs = new ArrayList<NameValuePair>(2);
								
								// Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar, 
								nameValuePairs.add(new BasicNameValuePair("username",et.getText().toString().trim()));  // $Edittext_value = $_POST['Edittext_value'];
								nameValuePairs.add(new BasicNameValuePair("password",pass.getText().toString().trim())); 
								httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
								//Execute HTTP Post Request
								response=httpclient.execute(httppost);
						
								ResponseHandler<String> responseHandler = new BasicResponseHandler();
								final String response = httpclient.execute(httppost, responseHandler);
								System.out.println("Response : " + response); 
								runOnUiThread(new Runnable() {
								    public void run() {
								    	tv.setText("Response from PHP : " + response);
										dialog.dismiss();
								    }
								});
								
								if(response.equalsIgnoreCase("User Found")){
									runOnUiThread(new Runnable() {
									    public void run() {
									    	Toast.makeText(MobileHyperMartActivity.this,"Login Success", Toast.LENGTH_SHORT).show();
									   
									    }
									});
									
									startActivity(new Intent(MobileHyperMartActivity.this, dashboard.class));
								}else{
									showAlert();				
								}
								
							}catch(Exception e){
								dialog.dismiss();
								System.out.println("Exception : " + e.getMessage());
							}	
					    
					    }
					  }).start();				
			}
		});
        
     // Link to Register Screen
        btnLinkToRegister.setonclickListener(new View.onclickListener() {

     			public void onclick(View v) {
     				Intent i = new Intent(MobileHyperMartActivity.this,
     						RegisterActivity.class);
     				
     				startActivity(i);
     				startActivityForResult(i, 0);
     				finish();
     			}
     		});
    }
  
	public void showAlert(){
		MobileHyperMartActivity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(MobileHyperMartActivity.this);
		    	builder.setTitle("Login Error.");
		    	builder.setMessage("User not Found.")  
		    	       .setCancelable(false)
		    	       .setPositiveButton("OK", new DialogInterface.onclickListener() {
		    	           public void onclick(DialogInterface dialog, int id) {
		    	           }
		    	       });		    	       
		    	AlertDialog alert = builder.create();
		    	alert.show();		    	
		    }
		});
		
	
}


even if there is no code in the register onclick the application stops..

This post has been edited by polens: 28 June 2012 - 06:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: not going to next activity help!

#2 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 849
  • Posts: 2,591
  • Joined: 29-July 11

Re: not going to next activity help!

Posted 30 June 2012 - 09:28 PM

Logcat says this is your problem:

nameValuePairs = new ArrayList<NameValuePair>(2);



assuming the code file you pasted is RegisterActivity.java
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1