Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code:
- /*
- * Copyright (C) 2013 Code Here Now - A subsidiary of Mobs & Geeks
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the
- * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package com.codeherenow.sicalculator;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.SeekBar;
- public class SICalculatorActivity extends Activity
- implements SeekBar.OnSeekBarChangeListener, View.OnClickListener{
- private int years;
- private TextView YT;
- private SeekBar bar;
- private EditText principal;
- private EditText interest;
- public EditText pvalue;
- public EditText ivalue;
- private double mPvalue = 0;
- private double mIvalue = 0;
- TextView fTextView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.sicalculator);
- TextView fTextView = (TextView) findViewById(R.id.finalText);
- pvalue = (EditText) findViewById(R.id.PA_field);
- ivalue = (EditText) findViewById(R.id.IR_field);
- bar = (SeekBar)findViewById(R.id.seekBar);
- bar.setOnSeekBarChangeListener(this);
- pvalue = (EditText) principal.getText();
- ivalue = (EditText) interest.getText();
- String s = principal.getText().toString();
- mPvalue = Double.parseDouble(s);
- String s2 = interest.getText().toString();
- mIvalue = Double.parseDouble(s2);
- YT = (TextView) findViewById(R.id.Years);
- }
- @Override
- public void onProgressChanged (SeekBar seekBar,int i, boolean b){
- years = i;
- YT.setText(years + " Year(s)");
- }
- @Override
- public void onStartTrackingTouch (SeekBar seekBar){
- }
- @Override
- public void onStopTrackingTouch (SeekBar seekBar){
- }
- @Override
- public void onClick(View view) {
- double finValue = mPvalue * (mIvalue/100) * years;
- fTextView.setText("The interest for " + pvalue + "at a rate of " + ivalue + "for " + years + "year(s) is " + finValue);
- }
- }
- LOGCAT:
- 03-04 18:48:14.527 984-984/com.codeherenow.sicalculator D/AndroidRuntime﹕ Shutting down VM
- 03-04 18:48:14.527 984-984/com.codeherenow.sicalculator W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa624c288)
- 03-04 18:48:14.531 984-984/com.codeherenow.sicalculator E/AndroidRuntime﹕ FATAL EXCEPTION: main
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.codeherenow.sicalculator/com.codeherenow.sicalculator.SICalculatorActivity}: java.lang.NullPointerException
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
- at android.app.ActivityThread.access$600(ActivityThread.java:130)
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
- at android.os.Handler.dispatchMessage(Handler.java:99)
- at android.os.Looper.loop(Looper.java:137)
- at android.app.ActivityThread.main(ActivityThread.java:4745)
- at java.lang.reflect.Method.invokeNative(Native Method)
- at java.lang.reflect.Method.invoke(Method.java:511)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
- at dalvik.system.NativeStart.main(Native Method)
- Caused by: java.lang.NullPointerException
- at com.codeherenow.sicalculator.SICalculatorActivity.onCreate(SICalculatorActivity.java:45)
- at android.app.Activity.performCreate(Activity.java:5008)
- at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
- at android.app.ActivityThread.access$600(ActivityThread.java:130)
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
- at android.os.Handler.dispatchMessage(Handler.java:99)
- at android.os.Looper.loop(Looper.java:137)
- at android.app.ActivityThread.main(ActivityThread.java:4745)
- at java.lang.reflect.Method.invokeNative(Native Method)
- at java.lang.reflect.Method.invoke(Method.java:511)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
- at dalvik.system.NativeStart.main(Native Method)
- 03-04 18:48:17.355 984-984/com.codeherenow.sicalculator I/Process﹕ Sending signal. PID: 984 SIG: 9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement