2015-04-23 169 views
-1

我在这段代码有此错误了java.lang.RuntimeException无法启动活动componentinfo

了java.lang.RuntimeException无法启动活动componentinfo

package estimatewall.example.com.estimatewall; 

import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class MainActivity extends ActionBarActivity { 

    EditText inputTxt; 
    EditText inputTxt1; 
    TextView setText; 

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

     inputTxt = (EditText) findViewById(R.id.editText); 

     // Store EditText in Variable 

     int val = Integer.parseInt(inputTxt.getText().toString()); 

     inputTxt1 = (EditText) findViewById(R.id.editText2); 

     // Store EditText in Variable 

     int val1 = Integer.parseInt(inputTxt1.getText().toString()); 

     float block1,block2; 
     final float sum; 
     block1=(val*12)/7; 
     block2=(val1*12)/10; 
     sum=block1*block2; 

     Button button = (Button) findViewById(R.id.button); 
     button.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 

       // Perform action on click 
       try { 
        TextView textView = (TextView) findViewById(R.id.textView3); 
        textView.setText("" + sum); 
       }catch (Exception e) 
       { 
        e.printStackTrace(); 
       } 


      } 
     }); 





    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 
+1

安置自己的logcat和.xml也 – Exception

+0

换句话说完整的错误堆栈,所以我们可以看到什么和在哪里抛出 –

+0

你定义支持库的样式?如果你还没有定义,那么用''Theme.AppCompat.Light''的样式来定义它 – Pankaj

回答

1

可能越来越NumberFormatException因为这里:

int val = Integer.parseInt(inputTxt.getText().toString()); 

试图c反转nullint

使用inputTxt.getText()内的点击监听按钮的onClick方法由用户来获取值输入EDITTEXT或设置XML一些默认值都EditText上的作为android:text="0"

相关问题