gpt4 book ai didi

android - Android错误: ActivityThread.performLaunchActivity

转载 作者:行者123 更新时间:2023-12-03 08:57:29 24 4
gpt4 key购买 nike

在进行一些更改以提高可用性之前,我的应用程序运行良好。现在,它始终显示此错误:ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2460
这是我的代码:

package de.nibor.theconverter;
public class MainActivity extends Activity implements OnItemSelectedListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);

//Gets all resources you need to get the input measure, calculate and printout the converted measure
final Button convertButton = (Button) findViewById(R.id.convertButton);
final EditText inputEditText = (EditText) findViewById(R.id.inputEditText);
final TextView hintTextView1 = (TextView) findViewById(R.id.hintTextView1);
final TextView hintTextView2 = (TextView) findViewById(R.id.hintTextView2);
final TextView outputTextView1 = (TextView) findViewById(R.id.outputTextView1);
final TextView outputTextView2 = (TextView) findViewById(R.id.outputTextView2);
final CharSequence inches = getResources().getString(R.string.inches);
final CharSequence cm = getResources().getString(R.string.cm);
final CharSequence feet = getResources().getString(R.string.feet);
final CharSequence cm_or_inch_hint_inputEditText = getResources().getString(R.string.cm_or_inch_hint_inputEditText);
final CharSequence cm_to_inch_hintTextView1 = getResources().getString(R.string.cm_to_inch_hintTextView1);
final CharSequence inch_to_cm_hintTextView2 = getResources().getString(R.string.inch_to_cm_hintTextView2);
final CharSequence are = getResources().getString(R.string.are);
final String measure_string = inputEditText.getText().toString();
final Double measure_double = Double.parseDouble(measure_string);



final Spinner measure_unit_spinner = (Spinner) findViewById(R.id.measure_unit_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.measure_units, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
measure_unit_spinner.setAdapter(adapter);
OnItemSelectedListener listener = new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
if(measure_unit_spinner.getSelectedItemPosition() == 0){
inputEditText.setHint(cm_or_inch_hint_inputEditText);

convertButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
printoutConvertedMeasure1();
printoutConvertedMeasure2();
}
private void printoutConvertedMeasure1() {

//first part: if cm convert to inch
hintTextView1.setText(cm_to_inch_hintTextView1);
Double cm_to_inch_decimal = (double) (measure_double/2.54);
Integer cm_to_inch_no_decimal = (int) (cm_to_inch_decimal*100.0);
Double cm_to_inch_output = (double) cm_to_inch_no_decimal/100.0;
outputTextView1.setText(measure_string + " " + cm + are + " " + cm_to_inch_output.toString() + " " + inches);
}

private void printoutConvertedMeasure2() {
//second part: if inch convert to cm
hintTextView2.setText(inch_to_cm_hintTextView2);
Double inch_to_cm_decimal = (double) (measure_double*2.54);
Integer inch_to_cm_no_decimal = (int) (inch_to_cm_decimal*100.0);
Double inch_to_cm_output = (double) (inch_to_cm_decimal/100.0);
outputTextView2.setText(measure_string + " " + cm + are + " " + inch_to_cm_output.toString() + " " + cm);
}



});

}


}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}

};
measure_unit_spinner.setOnItemSelectedListener(listener);






}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}
}

谁能帮我解决这个错误? (我想创建一个单位转换器应用)

最佳答案

删除以下代码行

convertButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
printoutConvertedMeasure1();
printoutConvertedMeasure2();
}

来自
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
if(measure_unit_spinner.getSelectedItemPosition() == 0){
inputEditText.setHint(cm_or_inch_hint_inputEditText);
//Your class variable
position=pos;
// Removed from here

并将此行添加到onCreate()
convertButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
switch(position)
{
case 0:
// Do Your Operation
printoutConvertedMeasure1();
printoutConvertedMeasure2();
break;
case 1:
// Do Your Operation
break;
// etc...
}
}

和onCreate()之外的这两个方法
private void printoutConvertedMeasure1() {

//first part: if cm convert to inch
hintTextView1.setText(cm_to_inch_hintTextView1);
Double cm_to_inch_decimal = (double) (measure_double/2.54);
Integer cm_to_inch_no_decimal = (int) (cm_to_inch_decimal*100.0);
Double cm_to_inch_output = (double) cm_to_inch_no_decimal/100.0;
outputTextView1.setText(measure_string + " " + cm + are + " " + cm_to_inch_output.toString() + " " + inches);
}

private void printoutConvertedMeasure2() {
//second part: if inch convert to cm
hintTextView2.setText(inch_to_cm_hintTextView2);
Double inch_to_cm_decimal = (double) (measure_double*2.54);
Integer inch_to_cm_no_decimal = (int) (inch_to_cm_decimal*100.0);
Double inch_to_cm_output = (double) (inch_to_cm_decimal/100.0);
outputTextView2.setText(measure_string + " " + cm + are + " " + inch_to_cm_output.toString() + " " + cm);
}

关于android - Android错误: ActivityThread.performLaunchActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19756764/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com