关于Android开发Activity.java里面main函数老是报错:main cannot be resolved or is not a field

/*下面是Android-src-HeightCalculator的程序*/
package com.demo.prH2;   

import android.app.Activity; 
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle; 
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;   
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox; 
import android.widget.*;
import android.widget.EditText;
import android.widget.TextView;


/*import java.text.DecimalFormat;   
import java.text.NumberFormat;   
import android.widget.RadioButton;   
import android.widget.Toast;     
/*  
* @author chengkaige * 
*/  
public class HeightCaculatorActivity extends Activity {   
/** Called when the activity is first created. */  
    private Button calculatorButton;     
    private EditText weightEditText; 
    private CheckBox manCheckBox;
    private CheckBox womanCheckBox;
    private TextView resultTextView;      
     
    @Override    
    public void onCreate(Bundle savedInstanceState) {     
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.main);    
        //调用创建视图的函数   
        calculatorButton =(Button)findViewById(R.id.calculator);
        weightEditText=(EditText)findViewById(R.id.weight);
        manCheckBox=(CheckBox)findViewById(R.id.man);
       womanCheckBox = (CheckBox)findViewById(R.id.woman);
        resultTextView=(TextView)findViewById(R.id.result);  
   }     
    private void onStar() {     
       super.onStart();  
       registerEvent();
    }     
    
    private void registerEvent() {     
    	calculatorButton.setOnClickListener(new OnClickListener(){     
        @Override    
        public void onClick(View v) {     
           if(!weightEditText.getText().toString().trim().equals("")){
        	MenuItem womanCheckBox = null;
			if(manCheckBox.isChecked()||womanCheckBox.isChecked())   
        	{
        		Double weight=Double.parseDouble(weightEditText.getText().toString());
        		StringBuffer sb=new StringBuffer();
        		sb.append("------评估结果-----\n");
        		if(manCheckBox.isChecked()){
        			sb.append("男性标准身高:");
        			double result=evaluateHeight(weight,"男");
        			sb.append((int)result+"厘米");	
        		}
        		if(womanCheckBox.isChecked()){
        			sb.append("女性标准身高:");
        			double result=evaluateHeight(weight,"女");
        			sb.append((int)result+"厘米");	
        		}
        		resultTextView.setText(sb.toString());
        	}else
        	{
        		showMessage("请选择性别呀!");
        	}
       }else{
    	   showMessage("请输入体重!");
       }   
           }
            
    	});  
    }
    private double evaluateHeight(double weight,String sex)
    {
    	double height;
    	if(sex=="男"){
    		height=170-(62-weight)/0.6;}
    	else{
    		height=158-(52-weight)/0.5;}
    	return height;}
    
    
    private void showMessage(String message)
    {
    	AlertDialog alert=new AlertDialog.Builder(this).create();
    	alert.setTitle("系统消息");
    	alert.setMessage(message);
    	alert.setButton("确定",new android.content.DialogInterface.OnClickListener(){
    		public void onClick(DialogInterface dialog,int whichButton){}
    	});
    	alert.show();
    }
    
    public boolean onCreateOptionMenu(Menu menu){
    	menu.add(Menu.NONE,1,Menu.NONE,"退出");
    	return super.onCreateOptionsMenu(menu);
    }
    
    public boolean onOptionItemSelected(MenuItem item){
    	switch(item.getItemId()){
    		case 1:
    			finish();
    			break;
    	}
    	return super.onOptionsItemSelected(item);
    }



底下是框架layout里面的程序,没有报错,就是上面的main一直报错,刚学安卓可能问题很简单可是很笨就是调不出来,啊啊啊啊!求大佬指导一波吖。。。。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical" >

    

   <LinearLayout

        android:id="@+id/linearLayout1"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_marginTop="20.0dp"

        android:gravity="center_horizontal"

        android:orientation="horizontal" >

        

        <TextView

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:gravity="center_horizontal"

            android:text="个人标准身高计算器"

            android:textSize="22.0dip"

            android:textStyle="bold" />

    </LinearLayout>


    <LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginTop="10dp"

        android:orientation="horizontal" >


        <TextView

            android:layout_width="120.0dip"

            android:layout_height="wrap_content"

            android:layout_marginLeft="5.0dip"

            android:text="请输入你的体重:" />


        <EditText

            android:id="@+id/weight"

            android:layout_width="150.0dip"

            android:layout_height="wrap_content"

            android:inputType="number" />


        <TextView

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="kg" />

    </LinearLayout>


    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:orientation="horizontal">

         <TextView 

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="请选择你的性别"

        android:layout_marginLeft="5.0dip" />


         <CheckBox

             android:id="@+id/man"

             android:layout_width="wrap_content"

             android:layout_height="wrap_content"

             android:text="男" />

         <CheckBox

             android:id="@+id/woman"

             android:layout_width="wrap_content"

             android:layout_height="wrap_content"

             android:text="女" />


    </LinearLayout>


    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal" 

        android:gravity="center_horizontal">

           <Button

        android:id="@+id/calculator"

        android:layout_marginTop="20dip"

        android:layout_width="150dip"

        android:layout_height="wrap_content"

        android:text="运算" />

    </LinearLayout>


    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

         android:orientation="horizontal" 

        android:gravity="center_horizontal">


        <TextView

            android:id="@+id/result"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginTop="10dip"

             />


    </LinearLayout>


    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:orientation="vertical" >

    </LinearLayout>


</LinearLayout>


格瑞克爱鲜荔枝
浏览 2891回答 2
2回答

习惯受伤

第一个问题:你看你的布局文件名字是否为main.xml,第二个的话private void onStar() 这一句有问题,重写基类方法名字和类型都要一样,还要有@Override的注解

慕瓜9220888

IXWVOYEBINVHVBSPNOWQCJXQJBIXKQWVZJEMAXTGSHORNZPFUTKHAXVMENCZZAWQTJHTGLOOSDMEZQJIQVYJXZWWGRLBCBCRQLYJBFYEXQARDCRCKNFLMLELIIFJTSVNLTUOGWUBGZSRRIPWGBNMMDNHIHVBKTKKRBCKTLLTGOYDCHQJGWDXCHWIJWTAUCHTSESIZ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