0
I have a file VigasFragment.java
with a button that when touched should open the 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 believe the error is in the code of VigMetBiapsb.java
because when I leave only the method onCreate()
within the class VigMetBiapsb
, to Activity
opens normally.
Errors of the Logcat at the touch of the button btnBiapsb
Errors of the Logcat at the touch of the button btnBiapsb
Edeilton, we can’t guess the problem without you including the stacktrace about the mistake. If you can, include it in your question.
– Wakim
You’re right, @Wakim. I’ve edited the question, I think it’s clearer now.
– EdeiltonSO