Need some help debugging my program

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

Need some help debugging my program

Postby bloonlabs » Sun Jan 20, 2008 3:03 am

Hi guys... This is my first entrance into the world of JAVA, and as such I am bumbling around like a blind guy in a room full of pillars. Basically I am designing a program called Project Wilfred, but have hit a spot where I simply can't go on... For some unknown reason whenever I try to call my options.class file the whole thing blows up. Here are some code snippets:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void gotoOptions() { //In my main class
  3.  
  4.         Intent i = new Intent(this, Options.class);
  5.  
  6.         startSubActivity(i, ACTIVITY_OPTIONS);
  7.  
  8.     }
  9.  
  10.  
  11.  
  12. ///////////////  Now my options class:
  13.  
  14.  
  15.  
  16. package com.android.project.wilfred;
  17.  
  18.  
  19.  
  20. import android.app.Activity;
  21.  
  22. import android.content.SharedPreferences;
  23.  
  24. import android.os.Bundle;
  25.  
  26. import android.view.View;
  27.  
  28. import android.widget.Button;
  29.  
  30. import android.widget.RadioGroup;
  31.  
  32.  
  33.  
  34. public class Options extends Activity implements RadioGroup.OnCheckedChangeListener {
  35.  
  36.        
  37.  
  38.         private String PREFS_NAME;
  39.  
  40.         private String PREFS_THEME;
  41.  
  42.         private String PREFS_PUBLICMAP;
  43.  
  44.        
  45.  
  46.     private final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
  47.  
  48.     private final SharedPreferences.Editor editor = settings.edit();
  49.  
  50.        
  51.  
  52.     @Override
  53.  
  54.     protected void onCreate(Bundle icicle) {
  55.  
  56.         super.onCreate(icicle);
  57.  
  58.         PREFS_NAME = getString(R.string.p_name);
  59.  
  60.         PREFS_THEME = getString(R.string.p_theme);
  61.  
  62.         PREFS_PUBLICMAP = getString(R.string.p_public);
  63.  
  64.         loadPreferences();
  65.  
  66.     }
  67.  
  68.    
  69.  
  70.         public void loadPreferences() {
  71.  
  72.         //TODO: Keep adding to this!
  73.  
  74.        
  75.  
  76.         final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
  77.  
  78.         if(settings.getBoolean(PREFS_THEME, false)) setTheme(android.R.style.Theme_Dark);
  79.  
  80.         else setTheme(android.R.style.Theme_White);
  81.  
  82.         //TODO: Change to custom colors eventually, for now just 2 themes (black-on-white, white-on-black)
  83.  
  84.        
  85.  
  86.         setOptions();
  87.  
  88.         }
  89.  
  90.        
  91.  
  92.         public void setOptions() {
  93.  
  94.        
  95.  
  96.         setContentView(R.layout.options);
  97.  
  98.        
  99.  
  100.         RadioGroup o_radioGroupTheme = (RadioGroup) findViewById(R.id.o_radioGroupTheme);
  101.  
  102.         RadioGroup o_radioGroupMap = (RadioGroup)       findViewById(R.id.o_radioGroupMap);
  103.  
  104.        
  105.  
  106.         o_radioGroupTheme.setOnCheckedChangeListener(this);
  107.  
  108.         o_radioGroupMap.setOnCheckedChangeListener(this);
  109.  
  110.        
  111.  
  112.         //This button handles submitting changed options TODO: disable it if no options to be changed
  113.  
  114.         Button b_save = (Button) findViewById(R.id.b_save);
  115.  
  116.         b_save.setOnClickListener(new Button.OnClickListener() {
  117.  
  118.             public void onClick(View v) {
  119.  
  120.                 editor.commit();
  121.  
  122.                 setResult(RESULT_OK);
  123.  
  124.                 finish();
  125.  
  126.             }
  127.  
  128.         });
  129.  
  130.        
  131.  
  132.         //This button cancels changes
  133.  
  134.         Button b_cancel = (Button) findViewById(R.id.b_cancel);
  135.  
  136.         b_cancel.setOnClickListener(new Button.OnClickListener() {
  137.  
  138.             public void onClick(View v) {
  139.  
  140.                 setResult(RESULT_CANCELED);
  141.  
  142.                 finish();
  143.  
  144.             }
  145.  
  146.         });
  147.  
  148.        
  149.  
  150.     }
  151.  
  152.        
  153.  
  154.     public void onCheckedChanged(RadioGroup group, int checkedId) {
  155.  
  156.         if(checkedId == R.id.r_changetheme_white) editor.putBoolean(PREFS_THEME, true);
  157.  
  158.         if(checkedId == R.id.r_changetheme_black) editor.putBoolean(PREFS_THEME, false);
  159.  
  160.         if(checkedId == R.id.r_publicmap_yes) editor.putBoolean(PREFS_PUBLICMAP, true);
  161.  
  162.         if(checkedId == R.id.r_publicmap_no) editor.putBoolean(PREFS_PUBLICMAP, false);
  163.  
  164.     }
  165.  
  166. }
  167.  
  168.  
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


Its alot of code, but I really have no idea whats causing the problem and because of that I don't know what i can leave out. If you want to see all the code you can look at our public SVN here: http://projectwilfred.googlecode.com/svn/

Thanks a bundle!!
bloonlabs
Freshman
Freshman
 
Posts: 7
Joined: Tue Dec 04, 2007 12:05 am

Top

Postby plusminus » Sun Jan 20, 2008 1:33 pm

Hello bloonlabs,

the call (the first 5 lines) look right.
Probably the problem appears to be within the Options-Class itself (Constructor or Fields).
Try simplifying your problem, or build it from scratch, adding only some small parts of code until you can identify the "bad line".

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 bloonlabs » Sun Jan 20, 2008 9:32 pm

Thanks plusminus for the quick reply!

I will try your suggestion and hopefully find the error. Oh, and I was curious if my exit was correct:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. setResult(RESULT_OK);
  3.  
  4. finish();
  5.  
  6.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Is that correct? It should pass control back to the method that stated the sub activity and look for the onActivityResult function right? Thanks!!
bloonlabs
Freshman
Freshman
 
Posts: 7
Joined: Tue Dec 04, 2007 12:05 am

Postby Ishtar » Mon Jan 21, 2008 10:35 am

Hi

Your exit is perfect. And indeed onActivityResult will be called, you should override this method. Most likely if your program isn't working you get an exception somewhere. If you use logcat in eclipse you can easily see where did happend. One remark about your package:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.android.project.wilfred;
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Packages names should always be unique. The easiest way to guarantee they are, is to use a website url that you own. I don't think android.com is yours :wink:. You could change your package name into: com.googlecode.projectwilfred. In eclipse using Refactor->Rename on the package folder, should change this easily.

Ishtar
Ishtar
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Wed Jan 16, 2008 10:22 pm
Location: Netherlands

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 16 guests