Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I instantiate a class in android which is also an activity?
    text
    copied!<p>In android, how can I create a <code>constructor</code> for a <code>class</code> which is also an <code>Activity</code>?</p> <p>My problem is, <p>I want to have two activity classes (estimateFare and Mapping) which both send data to a an activity class (<code>CalculateFare</code>). Mapping takes the data from real time network info, whereas estimateFare takes data from user input. I want <code>CalculateFare</code> to be able to use the data from either class to perform the calculation, although I have run into trouble with the <code>onCreate</code> method and the constructor for <code>CalculateFare</code>. When the class is called during runtime of the application I get the following message in the <code>LogCat</code>;</p> <pre><code>Unable to instantiate activity ComponentInfo. </code></pre> <p>A snippet from CalculateFare is as follows;</p> <pre><code> public class CalculateFare extends Activity { TextView t; static long length; static int dist; static int mMonth; static int mDay; public static double fare; double rate1 = 0, rate2a, rate2b, rate3, rate4a, rate4b; int remDist = 0; double remLength; private static int TTS_DATA_CHECK = 1; private TextToSpeech tts = null; private boolean ttsIsInit = false; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fare); } public CalculateFare(long length, int dist, int mMonth, int mDay) { } public static void setLength(long l) { length = l; } public static void setDist(int d) { dist = d; } public static void setDate(int m, int d) { mMonth = m; mDay = d; } public void calc() { </code></pre> <p>Any Advice much appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload