Solved

Having Big Problems With Android Project

Posted on 2011-09-24
5
257 Views
Last Modified: 2012-06-22
This is my first Android project, and I'm having quite a bit of difficulty with it. First I will attach the code, then ask my questions:

package com.jaylefler.restaurants;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import android.util.Log;


public class RestaurantList extends Activity {
	

	//private ArrayAdapter<String> dataAdapter;
	
	//final ArrayList<String> restaurantArray = new ArrayList<String>();
	
	//ListView myList = (ListView) findViewById(R.id.restaurants);
		
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final EditText restaurantName = (EditText) findViewById(R.id.name);
    	final EditText restaurantAddress = (EditText) findViewById(R.id.addr);
    	final RadioGroup restaurantType = (RadioGroup) findViewById(R.id.types);
    	final Button saveRestaurantInfo = (Button) findViewById(R.id.save);
        
        saveRestaurantInfo.setOnClickListener(new Button.OnClickListener() {

			@Override
			public void onClick(View v) {
				
				String restName = restaurantName.getText().toString();
				String restAddr = restaurantAddress.getText().toString();
				String deliveryType = "";
				
				int foodDeliveryType = restaurantType.getCheckedRadioButtonId();
				
				// If text fields are blank or radio button isn't selected clear all fields. 
				if (restName == "" || restAddr == "" || foodDeliveryType == -1) {
					restaurantName.setText("");
					restaurantName.setFocusable(true);
					restaurantAddress.setText("");
					restaurantType.clearCheck();
				}
				// Determine which radio group button has been selected based on the id. 
				else {
					if (foodDeliveryType == 0)
						deliveryType = "Take-Out";
					else if (foodDeliveryType == 1)
						deliveryType = "Sit-Down";
					else 
						deliveryType = "Delivery";
					
					String restaurantInfo = restName + " - " + restAddr + " - " + deliveryType;
					//restaurantArray.add(restaurantInfo);
					Log.d("JAY", "Restaurant Info reads: " + restaurantInfo + ".");
				}
			}
        	
        });
        
                
        
        //dataAdapter = new ArrayAdapter<String>(this, R.id.restaurants, restaurantArray);
        
    }
       // myList.setAdapter(dataAdapter);
}

Open in new window


My first problem is, in my "if (restName == "" || ...." condition, for some reason the program is always performing this condition, even when restName and restAddr aren't blank).

Also, during the debugger phase, on the "restaurantName.setFocusable(true);" line I get a Class File Editor - Source not found error. I have no idea what this means.

I have more then just these problems, but they are keeping me from going further with this project.

Thanks,
AppDevRookie
0
Comment
Question by:InquisitiveProgrammer
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:themrrobert
Comment Utility
Well your first answer is most likely because you are doing 3 OR comparissons, so if any are true, the code will execute.

If either is blank, OR if foodDeliveryType == -1 then the code runs, so my guess is that one of those is true, the only logical answer.

Check the values of all 3 with the debugger or output each into the log before (and maybe after) running the if check to verify this.

As far as the second error, i've encountered it myself and it's usually due to a configuration error. Only experimenting and becoming very familiar with the plethora of options available to android developers will give you the knowledge needed to figure this out on your quickly, but here are a few sources which could point you in the right direction: (ie, many causes)

http://www.groupsrv.com/computers/about618983.html

Try cleaning/updating the project (under "Android Tools")

Also, ensure that all of the source files have no X icon, and be sure your includes are complete, but most likely its a linking /config error.
0
 
LVL 1

Author Comment

by:InquisitiveProgrammer
Comment Utility
I have checked the properties while the debugger was running and when none of the conditions were met, the code still ran.

As for the link you provided, that was dated 2009 and the "help" provided was outdated.
0
 
LVL 16

Expert Comment

by:Peter Kwan
Comment Utility
I think the logic for the if clause should be:

if ("".equals(restName) || "".equals(restAddr) || foodDeliveryType == -1) {
0
 
LVL 13

Accepted Solution

by:
themrrobert earned 500 total points
Comment Utility
pk's logic  should work, the java-like framework should let his code work.

However the issue you are facing with the code is the same issue that has existed with eclipse and android sdk since 2009. There isn't one magic solution to make it work.

Even if you posted your entire code in a zip file, I could try to get it to work, and i may or may not have any trouble getting it to work, and if i do encounter your issue, my fix may not be the same fix for you.

if you want to upload your project I am sure i can trace the cause of your #2 issue and get it working on my end, but unless i'm actually working on the project i can only point you in the direction of places to look.

Best of luck :) hope you get it solved, the information is out there, you shouldn't be stuck for long
0
 
LVL 1

Author Comment

by:InquisitiveProgrammer
Comment Utility
Well, I'm not sure what I did, but I reinstalled Eclipse and the Android SDK and then imported the project and it was working fine.

In order to give points to someone, I hope that someone can answer this question:

I have a RadioGroup called restaurantType that has three buttons inside of it.

I know I can use restaurant.getCheckedRadioButtonId() in order to see if the radio buttons are checked

 
int foodDeliveryType = restaurantType.getCheckedRadioButtonId();
			
				// If any user requested info is missing, clear fields. 
				if (restName.isEmpty() || restAddr.isEmpty() || foodDeliveryType == -1) 
					clearFields();
				else {
					// Determine which radio group button has been selected.
					if (takeOut.isChecked())
						deliveryType = "Take-Out";
					else if (sitDown.isChecked())
						deliveryType = "Sit-Down";
					else 
						deliveryType = "Delivery"; // only other available option

Open in new window


I want to know if I can reference the text fields of the radio buttons without having to reference the buttons themselves. takeOut and sitDown are references to two of the Buttons in the RadioGroup.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
Introduction Everyone is using a smartphone these days. Contacts, messages, applications, documents, bookmarks, pictures, videos and other stuff which you created and are present only on your device come under the umbrella called “Personal Data”.…
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now