variable value other class

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

variable value other class

Postby rmeph » Wed Dec 26, 2007 3:49 pm

I have first.java.........In we use xml file

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class friendfind extends Activity  {
  2.  
  3. public String Location = new String("ena");
  4.  
  5.  
  6.  
  7.    @Override
  8.  
  9.    protected void onCreate(Bundle icicle) {
  10.  
  11.          super.onCreate(icicle);
  12.  
  13.          setContentView(R.layout.search);
  14.  
  15.         final Intent i1 = new Intent(this, friend.class);
  16.  
  17.         Button addbutton = (Button) findViewById(R.id.button);  
  18.  
  19.           addbutton.setOnClickListener(new View.OnClickListener() {  
  20.  
  21.             public void onClick(View v) {  
  22.  
  23.                   // Perform action on click  
  24.  
  25.                  Location =((EditText)findViewById(R.id.location)).getText().toString();
  26.  
  27.              startSubActivity(i1,0);
  28.  
  29.               }
  30.  
  31.              });
  32.  
  33. }
  34.  
  35. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4



and In second class we access Location variable value

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class friend extends ListActivity {
  2.  
  3. friendfind f=new friendfind();
  4.  
  5. protected void onCreate(Bundle icicle) {
  6.  
  7.       super.onCreate(icicle);
  8.  
  9.      
  10.  
  11.      Log.i(TAG,"Location  ="+f.Location);
  12.  
  13. }
  14.  
  15. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



but it's show NULLPOINTER error in second class
How to access value in second class????
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Top

Postby plusminus » Wed Dec 26, 2007 10:49 pm

Hello rmeph,

Probably "f" is null, because String-concatenation with null-Objects is possible :!:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 Object o = null;
  2.                 String s = "o is: " + o; // --> 'o is: null'
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


So it doesn't happen, if you use no xml-Layouting :?:

Have a look at :src: this tutorial on how to pass data to SubActivities.

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: No registered users and 10 guests