Advertisement
MtDewFella

Code 2

Mar 4th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.49 KB | None | 0 0
  1. Code:
  2.  
  3. /*
  4.  * Copyright (C) 2013 Code Here Now - A subsidiary of Mobs & Geeks
  5.  *
  6.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  7.  * except in compliance with the License. You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software distributed under the
  12.  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  13.  * either express or implied. See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package com.codeherenow.sicalculator;
  17.  
  18. import android.app.Activity;
  19. import android.os.Bundle;
  20. import android.view.View;
  21. import android.widget.EditText;
  22. import android.widget.TextView;
  23. import android.widget.SeekBar;
  24.  
  25. public class SICalculatorActivity extends Activity
  26.         implements SeekBar.OnSeekBarChangeListener, View.OnClickListener{
  27.     private int years;
  28.     private TextView YT;
  29.     private SeekBar bar;
  30.     private EditText principal;
  31.     private EditText interest;
  32.     public EditText pvalue;
  33.     public EditText ivalue;
  34.     private double mPvalue = 0;
  35.     private double mIvalue = 0;
  36.     TextView fTextView;
  37.  
  38.     @Override
  39.     protected void onCreate(Bundle savedInstanceState) {
  40.         super.onCreate(savedInstanceState);
  41.         setContentView(R.layout.sicalculator);
  42.         TextView fTextView = (TextView) findViewById(R.id.finalText);
  43.         pvalue = (EditText) findViewById(R.id.PA_field);
  44.         ivalue  = (EditText) findViewById(R.id.IR_field);
  45.         bar = (SeekBar)findViewById(R.id.seekBar);
  46.         bar.setOnSeekBarChangeListener(this);
  47.         pvalue = (EditText) principal.getText();
  48.         ivalue = (EditText) interest.getText();
  49.         String s = principal.getText().toString();
  50.         mPvalue = Double.parseDouble(s);
  51.         String s2 = interest.getText().toString();
  52.         mIvalue = Double.parseDouble(s2);
  53.         YT = (TextView) findViewById(R.id.Years);
  54.  
  55.     }
  56.         @Override
  57.         public void onProgressChanged (SeekBar seekBar,int i, boolean b){
  58.             years = i;
  59.             YT.setText(years + " Year(s)");
  60.  
  61.         }
  62.  
  63.         @Override
  64.         public void onStartTrackingTouch (SeekBar seekBar){
  65.  
  66.         }
  67.  
  68.         @Override
  69.         public void onStopTrackingTouch (SeekBar seekBar){
  70.  
  71.         }
  72.  
  73.     @Override
  74.     public void onClick(View view) {
  75.  
  76.         double finValue = mPvalue * (mIvalue/100) * years;
  77.         fTextView.setText("The interest for " + pvalue + "at a rate of " + ivalue + "for " + years + "year(s) is " + finValue);
  78.     }
  79. }
  80.  
  81.  
  82. LOGCAT:
  83.  
  84. 03-04 18:48:14.527      984-984/com.codeherenow.sicalculator D/AndroidRuntime﹕ Shutting down VM
  85. 03-04 18:48:14.527      984-984/com.codeherenow.sicalculator W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa624c288)
  86. 03-04 18:48:14.531      984-984/com.codeherenow.sicalculator E/AndroidRuntime﹕ FATAL EXCEPTION: main
  87.     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.codeherenow.sicalculator/com.codeherenow.sicalculator.SICalculatorActivity}: java.lang.NullPointerException
  88.             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
  89.             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
  90.             at android.app.ActivityThread.access$600(ActivityThread.java:130)
  91.             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
  92.             at android.os.Handler.dispatchMessage(Handler.java:99)
  93.             at android.os.Looper.loop(Looper.java:137)
  94.             at android.app.ActivityThread.main(ActivityThread.java:4745)
  95.             at java.lang.reflect.Method.invokeNative(Native Method)
  96.             at java.lang.reflect.Method.invoke(Method.java:511)
  97.             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  98.             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  99.             at dalvik.system.NativeStart.main(Native Method)
  100.      Caused by: java.lang.NullPointerException
  101.             at com.codeherenow.sicalculator.SICalculatorActivity.onCreate(SICalculatorActivity.java:45)
  102.             at android.app.Activity.performCreate(Activity.java:5008)
  103.             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  104.             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
  105.             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
  106.             at android.app.ActivityThread.access$600(ActivityThread.java:130)
  107.             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
  108.             at android.os.Handler.dispatchMessage(Handler.java:99)
  109.             at android.os.Looper.loop(Looper.java:137)
  110.             at android.app.ActivityThread.main(ActivityThread.java:4745)
  111.             at java.lang.reflect.Method.invokeNative(Native Method)
  112.             at java.lang.reflect.Method.invoke(Method.java:511)
  113.             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  114.             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  115.             at dalvik.system.NativeStart.main(Native Method)
  116. 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