-2
我有麻煩時,我試圖運行我的簡單的Android應用程序在我的系統 我爲這是不是我的系統上創建和那些行之有效的一些其他應用程序進行測試,但是當我編輯的我的系統上那麼這些應用程序也不會工作。我收到了許多錯誤運行Android應用程序
09-26 07:23:55.458: E/AndroidRuntime(1341): ... 11 more
at com.calculation.MainActivity.<init>(MainActivity.java:19)
at java.lang.Class.newInstanceImpl(Native Method)
: at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
爲什麼會出現這種 請幫我
package com.calculation;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.app.AlertDialog;
import android.content.DialogInterface;
public class MainActivity extends Activity {
EditText value1,value2;
Button add;
TextView display;
int num1=0, num2=0, total=0;
final AlertDialog alertdialog= new AlertDialog.Builder(MainActivity.this).create();
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
value1=(EditText)findViewById(R.id.input1);
value2=(EditText)findViewById(R.id.input2);
add=(Button)findViewById(R.id.btnadd);
display=(TextView)findViewById(R.id.result);
if(value1==null)
{
alertdialog.setTitle("AlertDialog");
alertdialog.setMessage("Please Enter a Valid Input");
alertdialog.setIcon(R.drawable.ic_launcher);
alertdialog.setButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "You Clicked OK" , Toast.LENGTH_LONG).show();
}
});
}
else if(value2==null)
{
alertdialog.setTitle("AlertDialog");
alertdialog.setMessage("Please Enter a Valid Input");
alertdialog.setIcon(R.drawable.ic_launcher);
alertdialog.setButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "You Clicked OK" , Toast.LENGTH_LONG).show();
}
});
}
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
num1=Integer.parseInt(value1.getText().toString());
num2=Integer.parseInt(value2.getText().toString());
total=num1+num2;
display.setText("ADDITION IS"+total);
}
});
}
}
發佈您的代碼 – Developer
在這裏發佈MainActivity.java。 –
發佈您的logcat的頂部。 – Szymon