Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 致命异常:main无法启动活动componentInfo_Android - Fatal编程技术网

Android 致命异常:main无法启动活动componentInfo

Android 致命异常:main无法启动活动componentInfo,android,Android,当我点击应用程序上的按钮时,我在日志中看到了上述错误。我将发布主活动和接收活动的代码 protected void onCreate(Bundle savedInstanceState)throws NullPointerException { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R

当我点击应用程序上的按钮时,我在日志中看到了上述错误。我将发布主活动和接收活动的代码

protected void onCreate(Bundle savedInstanceState)throws NullPointerException {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button button = (Button) findViewById(R.id.calculate);

    button.setOnClickListener(onSave);


}

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

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.calculate)
            calculate(v);
        }


    };
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent receive =getIntent();
    Bundle extras = receive.getExtras();
    String lowTierInvest = extras.getString(MainActivity.LOW);
    String medTierInvest = extras.getString(MainActivity.MED);
    String highTierInvest =extras.getString(MainActivity.HIGH);
    double tax = extras.getDouble(MainActivity.TAX);

    String TaxDisplay = String.format("Total annual tax amount is: R%0.2fc", tax);
    String lowTierDisplay = String.format("Compounded amount for low tier after 3 years is: R%0.2c", lowTierInvest);
    String medTierDisplay = String.format("Compounded amount for medium tier after 3 years is: R%0.2fc", medTierInvest);
    String highTierDisplay = String.format("Compounded amount for medium tier after 3 years is: R%0.2fc", highTierInvest);
    TextView textView = new TextView(this);
    textView.setTextSize(18);
    textView.setText(TaxDisplay +" \n"+ lowTierDisplay +"\n" +medTierDisplay + "\n" +highTierDisplay);
    setContentView(textView);

}
上面的计算onClick是我进行计算的方法,我将在下面发布它

public void calculate(View view){
    Intent calculate = new Intent(this,Show_returns.class);
    Bundle extras = new Bundle();
    EditText monthlySalaryString = (EditText)findViewById(R.id.monthly_salary);
    double monthlySalary = stripRFromInputString(monthlySalaryString.getText().toString());
    EditText ageString = (EditText)findViewById(R.id.age);
    int  age = Integer.parseInt(ageString.getText().toString());
    double tax = ComputeTax.taxableCategory(age, monthlySalary);
    double annualSalary = monthlySalary * 12;
    EditText percInvestView = (EditText) findViewById(R.id.perc_invest);
    double percInvest = stripRFromInputString(percInvestView.getText().toString())/100;
    EditText numYearsInvestString = (EditText) findViewById(R.id.num_years_invest);
    int numYearsInvest = Integer.parseInt(numYearsInvestString.getText().toString());
    EditText lowTierInvestView = (EditText) findViewById(R.id.low_tier_invest);
    double  lowTierInvest = stripRFromInputString(lowTierInvestView.getText().toString())/100;
    EditText medTierInvestView = (EditText) findViewById(R.id.med_tier_invest);
    double medTierInvest = stripRFromInputString(medTierInvestView.getText().toString())/100;
    EditText highTierInvestView = (EditText)findViewById(R.id.high_tier_invest);
    double highTierInvest = stripRFromInputString(highTierInvestView.getText().toString())/100;
    double lowTierInvestCompound = Investments.lowTierInvestmentReturns(annualSalary, tax, numYearsInvest, percInvest, lowTierInvest);
    double medTierInvestCompound = Investments.lowTierInvestmentReturns(annualSalary, tax, numYearsInvest, percInvest,medTierInvest);
    double highTierInvestCompound = Investments.lowTierInvestmentReturns(annualSalary, tax, numYearsInvest, percInvest,highTierInvest);
    String lowTierInvestString = String.valueOf(Math.floor(lowTierInvestCompound));
    String medTierInvestString = String.valueOf(Math.floor(medTierInvestCompound));
    String highTierInvestString = String.valueOf(Math.floor(highTierInvestCompound));

    extras.putString(LOW,lowTierInvestString);
    extras.putString(MED,medTierInvestString);
    extras.putString(HIGH,highTierInvestString);
    extras.putDouble(TAX,tax);
    startActivity(calculate);
}
下面是接收活动的代码

protected void onCreate(Bundle savedInstanceState)throws NullPointerException {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button button = (Button) findViewById(R.id.calculate);

    button.setOnClickListener(onSave);


}

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

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.calculate)
            calculate(v);
        }


    };
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent receive =getIntent();
    Bundle extras = receive.getExtras();
    String lowTierInvest = extras.getString(MainActivity.LOW);
    String medTierInvest = extras.getString(MainActivity.MED);
    String highTierInvest =extras.getString(MainActivity.HIGH);
    double tax = extras.getDouble(MainActivity.TAX);

    String TaxDisplay = String.format("Total annual tax amount is: R%0.2fc", tax);
    String lowTierDisplay = String.format("Compounded amount for low tier after 3 years is: R%0.2c", lowTierInvest);
    String medTierDisplay = String.format("Compounded amount for medium tier after 3 years is: R%0.2fc", medTierInvest);
    String highTierDisplay = String.format("Compounded amount for medium tier after 3 years is: R%0.2fc", highTierInvest);
    TextView textView = new TextView(this);
    textView.setTextSize(18);
    textView.setText(TaxDisplay +" \n"+ lowTierDisplay +"\n" +medTierDisplay + "\n" +highTierDisplay);
    setContentView(textView);

}
这是我的日志

08-30 09:03:07.667: E/AndroidRuntime(1237): FATAL EXCEPTION: main
08-30 09:03:07.667: E/AndroidRuntime(1237): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.investments/com.example.investments.Show_returns}: java.lang.NullPointerException
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.os.Looper.loop(Looper.java:137)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.app.ActivityThread.main(ActivityThread.java:5103)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at java.lang.reflect.Method.invokeNative(Native Method)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at java.lang.reflect.Method.invoke(Method.java:525)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at dalvik.system.NativeStart.main(Native Method)
08-30 09:03:07.667: E/AndroidRuntime(1237): Caused by: java.lang.NullPointerException
08-30 09:03:07.667: E/AndroidRuntime(1237):     at com.example.investments.Show_returns.onCreate(Show_returns.java:20)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.app.Activity.performCreate(Activity.java:5133)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-30 09:03:07.667: E/AndroidRuntime(1237):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-30 09:03:07.667: E/AndroidRuntime(1237):     ... 11 more
在您的计算中,实际上额外的内容并不附加在意图上。请尝试

Intent calculate = new Intent(this,Show_returns.class);
calculate.putExtra(LOW,lowTierInvestString);

问题是,您正在创建一个具有您发送的意图的捆绑包,但您从未将该捆绑包放入意图中,因此当您尝试获取它时,没有要获取的捆绑包


你需要做calculate.putextras

您是否可以发布logcat输出?您是否有stacktrace和您的异常,如果有,请发布。可能的重复项您是否已声明低、中、高等为公共静态最终字符串?请不要重复您的问题。使用其他信息编辑原始内容。我是否需要更改获取意图的方式?