我一直坚持这个问题,我得到错误:
class, interface or enum expected
任何帮助将不胜感激?我一直坚持这个问题,我的朋友们无法弄明白。
这是代码:
package com.example.vengelen.knitting;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;
import android.view.View;
import android.widget.Toast;
public class Rectangular extends ActionBarActivity {
EditText amount1;
EditText amount2;
EditText amount3;
TextView tt;
Button calculate;
double w=0;
double x=0;
double y=0;
double z=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rectangular);
initControls();
}
private void initControls()
{
amount1=(EditText)findViewById(R.id.editText);
amount2=(EditText)findViewById(R.id.editText3);
amount3=(EditText)findViewById(R.id.editText2);
tt=(TextView)findViewById(R.id.editText4);
calculate=(Button)findViewById(R.id.button9);
calculate.setOnClickListener(new Button.OnClickListener()
{public void onClick
(View v) { calculate();}});
}
EditText input;
EditText output;
Button one;
private void calculate()
{
w=Double.parseDouble(amount3.getText().toString());
x=Double.parseDouble(amount1.getText().toString());
y=Double.parseDouble(amount2.getText().toString());
z=(x+y)*(y+w);
tt.setText(Double.toString(z));
}
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rectangular);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_selector, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
您在方法onCreate
之前有不必要的结束括号:
}
^^
@Override
protected void onCreate(Bundle savedInstanceState)
这意味着编译器认为通过该大括号,您的类定义已经完成,然后看到一个新的方法定义应该在另一个类中,因此抱怨相同。作为最佳实践,您应始终格式化代码。