[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2382
  • Last Modified:

Java Error - Source Not found (Edit Source Lookup Path)

Hello,

I'm new to Android development and I'm running into errors that I can't figure out when running the application. I'm getting Source Not found when running debug in eclipse.

Please help. I attached the code that I'm running.
package com.CSV.Buescher;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;


public class OptionsPricingCalculatorActivity extends Activity {
    /** Called when the activity is first created. */
	Button myButton;
	TextView myStockPrice;
	TextView myExercise;
	TextView myDaysToExp;
	TextView myTreasuryReturn;
	TextView myVolatility;
	EditText myD1;
	EditText myD2;
	EditText myCallValue;
	EditText myPutValue;
	String sSP; //Stock Price String
	Double dSP; //Stock Price Double
	String sEX; //Exercise String
	Double dEX; //Exercise Double
	String sDTE; //Days To Expiration String
	Double dDTE; //Days To Expiration Double
	String sTR; //Treasury Return String
	Double dTR; //Treasury Return Double
	String sVL; //Volatility String
	Double dVL; //Volatility Double
	String sD1; //D1 String
	Double dD1; //D1 Double
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        myStockPrice = (TextView)findViewById(R.id.txtStockPrice);
        myExercise = (TextView)findViewById(R.id.txtExercise);
        myDaysToExp = (TextView)findViewById(R.id.txtDaysToExp);
        myTreasuryReturn = (TextView)findViewById(R.id.txtTreasuryReturn);
        myVolatility = (TextView)findViewById(R.id.txtVolatility);
        myD1 = (EditText)findViewById(R.id.lbld1);
        myD2 = (EditText)findViewById(R.id.lbld2);
        myCallValue = (EditText)findViewById(R.id.lblCallValue);
        myPutValue = (EditText)findViewById(R.id.lblPutValue);
        
        myButton.setOnClickListener(new View.OnClickListener(){
        	public void onClick(View v){
        		if (myStockPrice.getText().toString().equals("")){
        			Toast toast = Toast.makeText(getApplicationContext(), "Please enter a value for Stock Price.", Toast.LENGTH_LONG);
        			toast.show();
        		}
        		else if (myExercise.getText().toString().equals("")){
        			Toast toast = Toast.makeText(getApplicationContext(), "Please enter a value for Exercise Price.", Toast.LENGTH_LONG);
        			toast.show();
        		}
        		else if (myDaysToExp.getText().toString().equals("")){
        			Toast toast = Toast.makeText(getApplicationContext(), "Please enter a value for Days to Expiration.", Toast.LENGTH_LONG);
        			toast.show();
        		}
        		else if (myTreasuryReturn.getText().toString().equals("")){
        			Toast toast = Toast.makeText(getApplicationContext(), "Please enter a value for Treasury Return.", Toast.LENGTH_LONG);
        			toast.show();
        		}
        		else if (myVolatility.getText().toString().equals("")){
        			Toast toast = Toast.makeText(getApplicationContext(), "Please enter a value for Volatility.", Toast.LENGTH_LONG);
        			toast.show();
        		}
        		else{
        			sSP=myStockPrice.getText().toString();
        			dSP=Double.parseDouble(sSP);
        			sEX=myExercise.getText().toString();
        			dEX=Double.parseDouble(sEX);
        			sDTE=myDaysToExp.getText().toString();
        			dDTE=Double.parseDouble(sDTE);
        			sTR=myTreasuryReturn.getText().toString();
        			dTR=Double.parseDouble(sTR);
        			sVL=myVolatility.getText().toString();
        			dVL=Double.parseDouble(sVL);
        			
        			dD1 = ((Math.log(dSP/dEX)) + (dTR + 0.5*dVL*dVL)*(dDTE/365))/(dVL*(Math.sqrt(dDTE/365)));
        			sD1=Double.toString(dD1);
        			myD1.setText(sD1);
        		}
        	}

    		
        	});
    }
}


package com.CSV.Buescher;

import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.NormalDistributionImpl;

public class SDCalculator {
	 public Double Calc (Double a){
		 NormalDistributionImpl myND = new NormalDistributionImpl(); 
	        try {
				a = (myND.cumulativeProbability(a));
			} catch (MathException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
			}
		return a;
		
	 }
}


//Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1">
    <LinearLayout android:id="@+id/linearLayout1" android:layout_height="50dp" android:weightSum="1" android:layout_width="531dp">
       <TextView android:textAppearance="?android:attr/textAppearanceSmall" 
       			android:layout_height="wrap_content" 
       			android:text="Stock Price" 
       			android:lines="2" 
       			android:layout_width="57dp" 
       			android:gravity="center" 
       			android:id="@+id/lblStockPrice">
       </TextView>
       <TextView android:textAppearance="?android:attr/textAppearanceSmall" 
       			android:layout_height="wrap_content" 
       			android:text="Exercise or Strike Price" 
       			android:lines="2" 
       			android:layout_width="70dp" 
       			android:gravity="center" 
       			android:id="@+id/lblExercise">
       </TextView>
       <TextView android:textAppearance="?android:attr/textAppearanceSmall" 
       			android:layout_height="wrap_content" 
       			android:text="Days to Expiration" 
       			android:lines="2" 
       			android:layout_width="70dp" 
       			android:gravity="center" 
       			android:id="@+id/lblDaysToExp">
       </TextView>
       <TextView android:textAppearance="?android:attr/textAppearanceSmall" 
       			android:layout_height="wrap_content" 
       			android:text="Treasury Return" 
       			android:lines="2" 
       			android:layout_width="70dp" 
       			android:gravity="center" 
       			android:id="@+id/lblTreasuryReturn">
       </TextView>
       <TextView android:textAppearance="?android:attr/textAppearanceSmall" 
       			android:layout_height="wrap_content" 
       			android:text="Volatility (Std Dev)" 
       			android:lines="2" 
       			android:layout_width="70dp" 
       			android:gravity="center" 
       			android:id="@+id/lblVolatility">
       </TextView>
       <TextView android:textAppearance="?android:attr/textAppearanceSmall" 
       			android:layout_height="wrap_content" 
       			android:text="d1" 
       			android:lines="2" 
       			android:layout_width="40dp" 
       			android:gravity="center" 
       			android:id="@+id/lbld1">
       </TextView>
       <TextView android:textAppearance="?android:attr/textAppearanceSmall" 
       			android:layout_height="wrap_content" 
       			android:text="d2" 
       			android:lines="2" 
       			android:layout_width="40dp" 
       			android:gravity="center" 
       			android:id="@+id/lbld2">
       </TextView>
       <TextView android:textAppearance="?android:attr/textAppearanceSmall" 
       			android:layout_height="wrap_content" 
       			android:text="Call Value" 
       			android:lines="2" 
       			android:gravity="center"
       			android:layout_width="57dp" 
       			android:id="@+id/lblCallValue">
       </TextView>
       <TextView android:textAppearance="?android:attr/textAppearanceSmall" 
       			android:layout_height="wrap_content" 
       			android:text="Put Value" 
       			android:lines="2" 
       			android:gravity="center"
       			android:layout_width="57dp" 
       			android:id="@+id/lblPutValue">
       </TextView>
    </LinearLayout>
    <LinearLayout android:id="@+id/linearLayout2" android:layout_height="50dp" android:layout_width="531dp">
        <EditText android:layout_width="57dp" android:layout_height="wrap_content" android:inputType="numberDecimal" android:id="@+id/txtStockPrice"></EditText>
        <EditText android:layout_width="70dp" android:layout_height="wrap_content" android:inputType="numberDecimal" android:id="@+id/txtExercise"></EditText>
        <EditText android:layout_width="70dp" android:layout_height="wrap_content" android:inputType="numberDecimal" android:id="@+id/txtDaysToExp"></EditText>
        <EditText android:layout_width="70dp" android:layout_height="wrap_content" android:inputType="numberDecimal" android:id="@+id/txtTreasuryReturn"></EditText>
        <EditText android:layout_width="70dp" android:layout_height="wrap_content" android:inputType="numberDecimal" android:id="@+id/txtVolatility"></EditText>
        <TextView android:text="0.000" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="40dp" android:gravity="center" android:id="@+id/txtD1"></TextView>
        <TextView android:text="0.000" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="40dp" android:gravity="center" android:id="@+id/txtD2"></TextView>
        <TextView android:text="0.000" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="57dp" android:gravity="center" android:id="@+id/txtCallValue"></TextView>
        <TextView android:text="0.000" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="57dp" android:gravity="center" android:id="@+id/txtPutValue"></TextView>
    </LinearLayout>
    <Button android:layout_width="wrap_content" android:id="@+id/btnCalculate" android:layout_height="wrap_content" android:text="Calculate"></Button>
</LinearLayout>


//strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, OptionsPricingCalculatorActivity!</string>
    <string name="app_name">OptionsPricingCalculator</string>
</resources>


//manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.CSV.Buescher"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".OptionsPricingCalculatorActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>


debug errors are

<terminated>OptionsPricingCalculator [Android Application]	
	<disconnected>DalvikVM[localhost:8637]	
OptionsPricingCalculator [Android Application]	
	DalvikVM[localhost:8637]	
		Thread [<1> main] (Suspended (exception RuntimeException))	
			ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663	
			ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679	
			ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125	
			ActivityThread$H.handleMessage(Message) line: 2033	
			ActivityThread$H(Handler).dispatchMessage(Message) line: 99	
			Looper.loop() line: 123	
			ActivityThread.main(String[]) line: 4627	
			Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]	
			Method.invoke(Object, Object...) line: 521	
			ZygoteInit$MethodAndArgsCaller.run() line: 868	
			ZygoteInit.main(String[]) line: 626	
			NativeStart.main(String[]) line: not available [native method]	
		Thread [<6> Binder Thread #2] (Running)	
		Thread [<5> Binder Thread #1] (Running)

Open in new window

0
lulubell-b
Asked:
lulubell-b
  • 4
  • 2
1 Solution
 
RinilCommented:
hi,

It might be due to the fact that the android source code is not involved with android API, so while debugging that will take the control to any android class then the eclipse will throw error


http://android.opensourceror.org/2010/01/18/android-source/

below link helps in attaching the source with eclipse platform

please check it out
0
 
lulubell-bAuthor Commented:
Ok, now I'm able to see the source code. I get the following error on the first line

ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663      


Unsure how to fix?
catch (Exception e) {
            if (!mInstrumentation.onException(activity, e)) {
                throw new RuntimeException(
                    "Unable to start activity " + component
                    + ": " + e.toString(), e);
            }
        }

Open in new window

0
 
lulubell-bAuthor Commented:
Also found this in trace


09-11 16:30:50.218: ERROR/AndroidRuntime(394): Caused by: java.lang.ClassCastException: android.widget.TextView
09-11 16:30:50.218: ERROR/AndroidRuntime(394):     at com.CSV.Buescher.OptionsPricingCalculatorActivity.onCreate(OptionsPricingCalculatorActivity.java:47)
09-11 16:30:50.218: ERROR/AndroidRuntime(394):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-11 16:30:50.218: ERROR/AndroidRuntime(394):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-11 16:30:50.218: ERROR/AndroidRuntime(394):     ... 11 more
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ariohCommented:
According to Main.xml variables declaration should be as follows:
EditText myStockPrice;
EditText myExercise;
EditText myDaysToExp;
EditText myTreasuryReturn;
EditText myVolatility;
TextView myD1;
TextView myD2;
TextView myCallValue;
TextView myPutValue;

.................

myStockPrice = (EditText)findViewById(R.id.txtStockPrice);
myExercise = (EditText)findViewById(R.id.txtExercise);
myDaysToExp = (EditText)findViewById(R.id.txtDaysToExp);
myTreasuryReturn = (EditText)findViewById(R.id.txtTreasuryReturn);
myVolatility = (EditText)findViewById(R.id.txtVolatility);
myD1 = (TextView)findViewById(R.id.lbld1);
myD2 = (TextView)findViewById(R.id.lbld2);
myCallValue = (TextView)findViewById(R.id.lblCallValue);
myPutValue = (TextView)findViewById(R.id.lblPutValue);

Open in new window

0
 
lulubell-bAuthor Commented:
I'm confused. Did I just have them in the wrong order or did I call something a wrong type?

ok, now I get ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663      
 and the trace says the following:

09-12 01:49:33.918: ERROR/AndroidRuntime(445): Caused by: java.lang.NullPointerException
09-12 01:49:33.918: ERROR/AndroidRuntime(445):     at com.CSV.Buescher.OptionsPricingCalculatorActivity.onCreate(OptionsPricingCalculatorActivity.java:52)
09-12 01:49:33.918: ERROR/AndroidRuntime(445):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-12 01:49:33.918: ERROR/AndroidRuntime(445):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-12 01:49:33.918: ERROR/AndroidRuntime(445):     ... 11 more


Again, I'm new to android development and I have no clue on this error.

Thanks
0
 
ariohCommented:
For example

Main.xml:
  <EditText android:layout_width="70dp" android:layout_height="wrap_content" android:inputType="numberDecimal" android:id="@+id/txtVolatility"></EditText>

your code:
TextView myVolatility;
myVolatility = (TextView)findViewById(R.id.txtVolatility);

should be:
EditText myVolatility;
myVolatility = (EditText)findViewById(R.id.txtVolatility);

So, myVolatility is not TextView, it is EditText.
0
 
lulubell-bAuthor Commented:
Perfect, Thank you I got it to work.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now