"Button cannot be resolved to a type"

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

"Button cannot be resolved to a type"

Postby daro » Wed Oct 21, 2009 9:32 pm

Hi,

This is my first post but I have a big problem in my app. I need it working for 2 days of school. Help mi! :) SDK 1.5

Problem is:

Button evaluateBtn = (Button) findViewById(R.id.evaluate);



res/values/strings.xml

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <resources>
  3.     <string name="app_name">BloodAlcoholCalculator</string>
  4.     <string name="mass">Body mass (kg)</string>
  5.     <string name="percent">Alcohol percentage (%)</string>
  6.     <string name="quantity">Quantity (ml)</string>
  7.     <string name="gender">Gender</string>
  8.     <string name="gender_male">Male</string>
  9.     <string name="gender_female">Female</string>
  10.     <string name="concentration">Your blood-alcohol concentration</string>
  11.     <string name="evaluate">Evaluate</string>
  12.     <string name="error_missing_data">Error: missing data</string>
  13. </resources>
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


res/layout/main.xml

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
  3.     <TextView android:text="@string/mass" android:layout_height="wrap_content" android:layout_width="wrap_content"/>
  4.     <EditText android:id="@+id/mass" android:layout_height="wrap_content" android:layout_width="fill_parent" android:digits="1234567890" android:maxLength="3"/>
  5.     <TextView android:text="@string/percent" android:layout_height="wrap_content" android:layout_width="wrap_content"/>
  6.     <EditText android:id="@+id/percent" android:layout_height="wrap_content" android:layout_width="fill_parent" android:digits="1234567890" android:maxLength="2"/>
  7.     <TextView android:text="@string/quantity" android:layout_height="wrap_content" android:layout_width="wrap_content"/>
  8.     <EditText android:id="@+id/quantity" android:layout_height="wrap_content" android:layout_width="fill_parent" android:digits="1234567890" android:maxLength="4"/>
  9.     <RadioGroup android:id="@+id/gender" android:layout_height="wrap_content" android:layout_width="fill_parent">
  10.         <TextView android:text="@string/gender" android:layout_height="wrap_content" android:layout_width="fill_parent"/>
  11.         <RadioButton android:checked="false" android:text="@string/gender_male" android:id="@+id/gender_male"/>
  12.         <RadioButton android:checked="false" android:text="@string/gender_female" android:id="@+id/gender_female"/>
  13.     </RadioGroup>
  14.     <Button android:id="@+id/evaluate" android:text="@string/evaluate" android:layout_height="wrap_content" android:layout_width="fill_parent"/>
  15.     <TextView android:id="@+id/result" android:layout_height="fill_parent" android:layout_width="fill_parent" android:textSize="30px"/>
  16. </LinearLayout>
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


java

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package pl.daro.blood.alcohol.calc;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.widget.EditText;
  6. import android.widget.RadioGroup;
  7. import android.widget.TextView;
  8.  
  9.  
  10. public class CalculatorActivity extends Activity {
  11.  
  12.     private EditText mass = null;
  13.     private EditText percent = null;
  14.     private EditText quantity = null;
  15.     private RadioGroup gender = null;
  16.     private TextView result = null;
  17.  
  18.  
  19.     /** Called when the activity is first created. */
  20.     @Override
  21.     public void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.main);
  24.  
  25.         mass = (EditText) findViewById(R.id.mass);
  26.         percent = (EditText) findViewById(R.id.percent);
  27.         quantity = (EditText) findViewById(R.id.quantity);
  28.         gender = (RadioGroup) findViewById(R.id.gender);
  29.         result = (TextView) findViewById(R.id.result);
  30.  
  31.         Button evaluateBtn = (Button) findViewById(R.id.evaluate);
  32.     }
  33. }
  34. evaluateBtn.setOnClickListener(new View.OnClickListener() {
  35.     @Override
  36.     public void onClick(View pV) {
  37.         CalculatorActivity.this.evaluate();
  38.     }
  39. });
  40. private void evaluate() {
  41.     int massValue = Integer.valueOf(mass.getText().toString());
  42.     int percentValue = Integer.valueOf(percent.getText().toString());
  43.     int quantityValue = Integer.valueOf(quantity.getText().toString());
  44.     boolean isMan = gender.getCheckedRadioButtonId() == R.id.gender_male;
  45.  
  46.     float evaluationResult = percentValue * quantityValue * 80 / massValue / (isMan ? 70 : 60) / 100f;
  47.     String returnMsg = evaluationResult + "‰";
  48.     result.setText(returnMsg);
  49. }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


or all files:
http://www.mediafire.com/file/wdyntidz3 ... ulator.rar

Pls, help mi! My times is over. 48h
Attachments
BloodAlcoholCalculator.rar
(18.62 KiB) Downloaded 105 times
daro
Freshman
Freshman
 
Posts: 2
Joined: Wed Oct 21, 2009 9:20 pm

Top

Postby wiederke » Thu Oct 22, 2009 12:24 pm

Hi,

your brackets are wrong in CalcultorActivity around the anonymous View.OnClickListener. I fixed it and attached the fixed source.


Bye,

Torsten
Attachments
BloodAlcoholCalculator_fixed.zip
(33.39 KiB) Downloaded 513 times
wiederke
Experienced Developer
Experienced Developer
 
Posts: 72
Joined: Mon Mar 02, 2009 6:46 pm
Location: Germany

Postby daro » Thu Oct 22, 2009 8:29 pm

Thanks @wiederke
Everything works!
daro
Freshman
Freshman
 
Posts: 2
Joined: Wed Oct 21, 2009 9:20 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests