Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 5 years ago

android 錯誤找不到

小弟最近在學寫android不過怎麼大括號那邊都一直顯示錯誤 有大大能只點一下嗎

package com.example.test.protect;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

EditText txt1=(EditText)findViewById(R.id.editText1);

EditText txt2=(EditText)findViewById(R.id.editText2);

TextView tv1=(TextView)findViewById(R.id.textView1);

Button btn1=(Button)findViewById(R.id.button1);

btn1.setOnClickListener(BMI);

}

private OnClickListener BMI=new OnClickListener()

{

public void OnClick(View v)

{

double editText1=Double.parseDouble(txt1.getText().toString())/100;

double editText2=Double.parseDouble(txt2.getText().toString());

BMI=editText1/(editText2*editText2);

tv1.setText("your BMI:"+BMI);

}

};

} <-----錯在這裡

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

}

Update:

括號刪掉也是有錯 錯誤寫說syntax error是我語法有錯嗎

1 Answer

Rating
  • 5 years ago
    Best Answer

    你把括號刪掉即可!!!!

    自己對一下括號的數量~

    2014-08-15 10:05:19 補充:

    嗯嗯~~你的OnClickListener() 語法要在修一下

    因為我也沒有你寫的所有檔案~所以不容易知道你到底錯哪邊

    Source(s): 自己
Still have questions? Get your answers by asking now.