MainActivity is highlighted and an error is presented 'The nested type MainActivity cannot hide an enclosing type' Any help solving this issue would be appreciated. when i remove the first MainActivity the rest of the code becomes filled with errors?
package com.example.myfirstapp;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
@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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class MainActivity extends Activity implements OnClickListener {
EditText fuelCost;
EditText distance;
EditText milesPerGallon;
Button btn_1;
TextView result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fuelCost = (EditText) findViewById(R.id.fuelCost);
distance = (EditText) findViewById(R.id.distance);
milesPerGallon = (EditText) findViewById(R.id.milesPerGallon);
btn_1 = (Button) findViewById(R.id.btn_1);
result =(TextView) findViewById(R.id.result);
btn_1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
float num1 = 0;
float num2 = 0;
float num3 = 0;
float result = 0;
if (TextUtils.isEmpty(fuelCost.getText().toString())
|| TextUtils.isEmpty(distance.getText().toString())
|| TextUtils.isEmpty(milesPerGallon.getText().toString())) {
return;
}
num1 = Float.parseFloat(fuelCost.getText().toString());
num2 = Float.parseFloat(distance.getText().toString());
num3 = Folat.parseFloat(milesPerGallon.getText().toString());
switch (v.getId()) {
case R.id.btn_1:
result = ((num1 * 4.5461) * (num2 / num3)) / 100;
break;
default:
break;
}
result.setText("£" + result);
}
}
}