昨天它的工作完美,但今天显示消息“不幸的是,应用程序已经停止”,和logcat的显示“关闭虚拟机”。
这个应用程序的堆栈跟踪..
11-27 13:24:17.035: W/Trace(806): Unexpected value from nativeGetEnabledTags: 0
11-27 13:24:17.455: W/Trace(806): Unexpected value from nativeGetEnabledTags: 0
11-27 13:24:17.485: W/Trace(806): Unexpected value from nativeGetEnabledTags: 0
11-27 13:24:17.485: D/AndroidRuntime(806): Shutting down VM
11-27 12:30:51.683: D/AndroidRuntime(734): Shutting down VM
11-27 12:30:51.943: D/dalvikvm(734): GC_CONCURRENT freed 137K, 9% free 2625K/2880K,paused23ms+7ms, total 230ms
11-27 12:37:12.259: D/dalvikvm(878): newInstance failed: p0 i0 [0 a1
11-27 12:37:12.259: D/AndroidRuntime(878): Shutting down VM
11-27 12:43:22.839: D/dalvikvm(939): newInstance failed: p0 i0 [0 a1
11-27 12:43:22.878: D/AndroidRuntime(939): Shutting down VM
这是程序..
package com.raghuram.simplecalculator;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
public abstract class CalculatorActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculator);
OnClickListener addlisten= new OnClickListener()
{
public void onClick(View v)
{
EditText tx1=(EditText) findViewById(R.id.editText1);
EditText tx2=(EditText) findViewById(R.id.editText2);
EditText tx3=(EditText) findViewById(R.id.editText3);
Float res=Float.parseFloat(tx1.getText().toString()) + Float.parseFloat(tx2.getText().toString());
tx3.setText(Float.toString(res));
}
};
ImageButton a=(ImageButton) findViewById(R.id.imageButton1);
a.setOnClickListener(addlisten);
OnClickListener sublisten= new OnClickListener()
{
public void onClick(View v)
{
EditText tx1=(EditText) findViewById(R.id.editText1);
EditText tx2=(EditText) findViewById(R.id.editText2);
EditText tx3=(EditText) findViewById(R.id.editText3);
Float res1=Float.parseFloat(tx1.getText().toString()) - Float.parseFloat(tx2.getText().toString());
tx3.setText(Float.toString(res1));
}
};
ImageButton s=(ImageButton) findViewById(R.id.imageButton2);
s.setOnClickListener(sublisten);
OnClickListener mullisten= new OnClickListener()
{
public void onClick(View v)
{
EditText tx1=(EditText) findViewById(R.id.editText1);
EditText tx2=(EditText) findViewById(R.id.editText2);
EditText tx3=(EditText) findViewById(R.id.editText3);
Float res1=Float.parseFloat(tx1.getText().toString()) * Float.parseFloat(tx2.getText().toString());
tx3.setText(Float.toString(res1));
}
};
ImageButton m=(ImageButton) findViewById(R.id.imageButton3);
m.setOnClickListener(mullisten);
OnClickListener divlisten= new OnClickListener()
{
public void onClick(View v)
{
EditText tx1=(EditText) findViewById(R.id.editText1);
EditText tx2=(EditText) findViewById(R.id.editText2);
EditText tx3=(EditText) findViewById(R.id.editText3);
Float x=Float.parseFloat(tx2.getText().toString());
if(x>0)
{
Float res1=Float.parseFloat(tx1.getText().toString()) / Float.parseFloat(tx2.getText().toString());
tx3.setText(Float.toString(res1));
}
else
{
Context context = getApplicationContext();
CharSequence text = "Invalid number.";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
};
ImageButton d=(ImageButton) findViewById(R.id.imageButton4);
d.setOnClickListener(divlisten);
ImageButton e=(ImageButton) findViewById(R.id.imageButton5);
e.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
System.exit(0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_calculator, menu);
return true;
}
}
它显示了确切的结果昨天,但现在它forcely关闭..如何管理内存。