I keep getting null pointer exception

Put your problem here if it does not fit any of the other categories.

I keep getting null pointer exception

Postby fanar » Mon Jan 28, 2008 1:37 am

after i changed some stuff in my code i started getting a null pointer exception:

An error has occured in process droidorganize.passwordprotector. Unable to start activity ComponentInfo{droidorganize.passwordprotector/droidorganize.passwordprotector.PasswordProtector}:java.lang.NullPointerException.

However i do not remember what I changed and have tried commenting out parts of the code to get it working, yet i still get the null pointer. I have 2 acitivities. I commented out the part that calls the second activity so the null pointer is somewhere in the first one.

Here:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package drioidorganize.passwordprotector;
  3.  
  4.  
  5.  
  6.  
  7.  
  8. import android.app.Activity;
  9.  
  10. import android.content.Intent;
  11.  
  12. import android.os.Bundle;
  13.  
  14. import android.view.View;
  15.  
  16. import android.widget.Button;
  17.  
  18.  
  19.  
  20. public class PasswordProtector extends Activity {
  21.  
  22.     /** Called when the activity is first created. */
  23.  
  24.         private PassDB passDB;
  25.  
  26.        
  27.  
  28.     @Override
  29.  
  30.     public void onCreate(Bundle icicle) {
  31.  
  32.         super.onCreate(icicle);
  33.  
  34.         setContentView(R.layout.pass_login);
  35.  
  36.         passDB = new PassDB(this);
  37.  
  38.        
  39.  
  40.        
  41.  
  42.         Button confirmButton = (Button) findViewById(R.id.confirm);
  43.  
  44.  
  45.  
  46.        //checkIfSet();
  47.  
  48.        
  49.  
  50.         confirmButton.setOnClickListener(new View.OnClickListener() {
  51.  
  52.  
  53.  
  54.             public void onClick(View arg0) {
  55.  
  56.                 checkPassword();
  57.  
  58.             }
  59.  
  60.            
  61.  
  62.         });
  63.  
  64.     }
  65.  
  66.     private void checkIfSet(){
  67.  
  68.         android.util.Log.v("out",""+passDB.isPassSet());
  69.  
  70.         if(!passDB.isPassSet()){
  71.  
  72.                 Intent i = new Intent(this, SetPassword.class);
  73.  
  74.  
  75.  
  76.             startSubActivity(i,0);
  77.  
  78.                 /*
  79.  
  80.                 MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
  81.  
  82.             digest.update(...your data here...);
  83.  
  84.             byte[] hash = digest.digest();
  85.  
  86.             */
  87.  
  88.  
  89.  
  90.         }
  91.  
  92.     }
  93.  
  94.     private void checkPassword(){
  95.  
  96.        
  97.  
  98.     }
  99.  
  100. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


if someone could help me i would appreciate it.
fanar
Freshman
Freshman
 
Posts: 4
Joined: Mon Jan 07, 2008 6:38 am

Top

Postby cabernet1976 » Mon Jan 28, 2008 4:06 am

Hi fanar,

Your code seems simply and OK.
If the view isn't generated in onCreate, system will throw NullPointerException. So can you dobule check this line?
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setContentView(R.layout.pass_login);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


e.g. is the layout fine?
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Postby plusminus » Mon Jan 28, 2008 2:56 pm

Hello fanar,

on which line exactly does the NullPointerException occur :?:
if it is this line:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. confirmButton.setOnClickListener(new View.OnClickListener() {
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


there is very probably a problem with the xml-file you loaded :!:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby fanar » Tue Jan 29, 2008 9:56 pm

um how do i know which line the exception is thrown?
fanar
Freshman
Freshman
 
Posts: 4
Joined: Mon Jan 07, 2008 6:38 am

Postby plusminus » Wed Jan 30, 2008 12:38 am

Hello fanar,

using the standard debugging tool.
Or is it thrown before it reaches the first line in onCreate() :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 21 guests