I have a VigasFragment.java
file with a button that when touched should open Activity
VigMetBiapsb.java
, however some error occurs, closing the application.
VigasFragment.java:
public class VigasFragment extends Fragment {
Button btnBiapsb;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.vigas_fragment, container, false);
// ////////////////////////////////////////////////////////////////////////////////
btnBiapsb = (Button) rootView.findViewById(R.id.biapsb);
btnBiapsb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intBiapsb = new Intent(v.getContext(), VigMetBiapsb.class);
startActivityForResult(intBiapsb, 0);
}
});
// ////////////////////////////////////////////////////////////////////////////////
return rootView;
}// fecha onCreateView
}
VigMetbiapsb.java:
public class VigMetBiapsb extends Activity {
int porctAlt, porctLarg;
EditText edtVao = (EditText) findViewById(R.id.vao);
final double edtVaoNum = Double.parseDouble(edtVao.getText().toString());
Button calcBiapsb = (Button) fi
ndViewById(R.id.calc_biapsb);
TextView secaoBiapsb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vigmet_biapsb);
// Spinner
Spinner spnCargas = (Spinner) findViewById(R.id.spn_cargas);
ArrayAdapter<CharSequence> spnAdapter = ArrayAdapter.createFromResource(this, R.array.str_cargas, R.layout.spinner_style);
spnAdapter.setDropDownViewResource(R.layout.spinner_dropdown_style);
spnCargas.setAdapter(spnAdapter);
// Spinner
spnCargas.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> spnAdpView, View v, int carga, long id) {
if(spnAdpView.getItemAtPosition(carga).toString() == "Cargas pequenas"){ porctAlt = 4; porctLarg = 40; }
else if(spnAdpView.getItemAtPosition(carga).toString() == "Cargas médias"){ porctAlt = 5; porctLarg = 50; }
else { porctAlt = 6; porctLarg = 60; }
}// fecha onItemSelected
public void onNothingSelected(AdapterView<?> arg0){}
}//fecha OnItemSelectedListener
); // fecha setOnItemSelectedListener
calcBiapsb.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(edtVaoNum != 0){
double alt = edtVaoNum * porctAlt;
double larg = alt / 100 * porctLarg;
secaoBiapsb = (TextView) findViewById(R.id.valorsec);
secaoBiapsb.setText(String.valueOf(alt)+" x "+String.valueOf(larg));
}
else {
Toast.makeText(getApplicationContext(), "Informe o tamanho do vão", Toast.LENGTH_SHORT).show();
}
}
});
} //fecha onCreate
}
I think the error is in the code of VigMetBiapsb.java
because when I leave only the onCreate()
method within the VigMetBiapsb
class, Activity
normally opens.
LogCat errors by touching the btnBiapsb
LogCat Errors by touching the btnBiapsb