运行Android应用程序

时间:2013-09-26 11:32:54

标签: android-emulator 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);
            }
        });


    }

}

1 个答案:

答案 0 :(得分:0)

问题是api级别被测试的应用程序是在多年前在不同的api级别和环境中创建的,因此警报对话框错误即将到来 警报对话框可以这样

private void showinvalidemail() {
        // TODO Auto-generated method stub
        AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this);
        dialogbuilder.setTitle("Invalid Email");
        dialogbuilder.setMessage("Please Enter Valid Email");
        dialogbuilder.setIcon(R.drawable.mexit);
        dialogbuilder.setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        // TODOAuto-generated method stub
                        Toast.makeText(getApplicationContext(),
                                "You Clicked OK", Toast.LENGTH_LONG).show();
                    }
                });
        AlertDialog alertdialog = dialogbuilder.create();
        alertdialog.show();
    }