2013-09-26 263 views
-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); 
      } 
     }); 


    } 

}

+0

發佈您的代碼 – Developer

+0

在這裏發佈MainActivity.java。 –

+0

發佈您的logcat的頂部。 – Szymon

回答

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(); 
    }