Results 1 to 5 of 5
- 06-05-2011, 09:17 PM #1
Creating a class that extends Activity and implements OnClickListener
Is it legal to create a class that extends Activity and implements OnClickListener?
I need to start an Activity inside of my onClickListener class, so I had to have the class extend Activity, but my code keeps blowing up with a nullPointerException on the line startActivity(myIntent). Could the reason be the extends and implements on my class?
- 06-07-2011, 04:19 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
No, you'll get a NullPointerException because you attempt to dereference a variable that is null.
If the offending line is "startActivity(myIntent);" (in the absence of code and the exact and entire compiler message that's a guess) then it looks like the culprit is myIntent. Look at where you thought you had given this variable a nonnull value and try to figure out why that didn't happen.
It's not really clear from your description why a click listener would be an activity, rather than just starting the activity based on whatever the intent was. Perhaps a brief code example together with a description of the expected behaviour would help.
- 06-08-2011, 11:47 PM #3
I am extending Activity because inside of my listener is when my listener is triggered I want to start a new activity, and the listener class does not understand startActivity(myActivity)
- 01-17-2012, 12:31 AM #4
Member
- Join Date
- Oct 2011
- Posts
- 5
- Rep Power
- 0
Re: Creating a class that extends Activity and implements OnClickListener
hi all,
I have a code but it doesn't work ! can you please help me on it? it will show graph in android field. but startActivity doesn't properly !! can anyone help me please ?
<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>
int DataCnt = 6;
SortedData[][] //This is an 2D array
---------------
[[FASTWEB-2012, -66, 0], [FASTWEB-1-001CA2B8E818, -85, 0], [FASTWEB-2012, -66, 5], [FASTWEB-1-001CA2B8E818, -85, 5], [FASTWEB-2012, -66, 10], [FASTWEB-1-001CA2B8E818, -85, 10]]
TerminalCount[][] ////This is an 2D array
-------------------
[[FASTWEB-2012, 3], [FASTWEB-1-001CA2B8E818, 3]]
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
switch (TermDimenSnRow) //suppose I have TermDimenSnRow = 2
{
case 1:
break;
case 2:
TimeSeries series2 = new TimeSeries("WiFi 1");
TimeSeries series3 = new TimeSeries("WiFi 2");
for( int i2 = 0; i2 < DataCnt; i2++)
{
if(TerminalCount[0][0].equals(SortedData[i2][0]))
{
int WifiRSSIVal = (Integer.parseInt(String.valueOf(SortedData[i2][1])));
int WifiTimeVal = (Integer.parseInt(String.valueOf(SortedData[i2][2])));
series2.add(WifiRSSIVal, WifiTimeVal);
}
}
for( int i3 = 0; i3 < DataCnt; i3++)
{
if(TerminalCount[1][0].equals(SortedData[i3][0]))
{
int WifiRSSIVal = (Integer.parseInt(String.valueOf(SortedData[i3][1])));
int WifiTimeVal = (Integer.parseInt(String.valueOf(SortedData[i3][2])));
series3.add(WifiRSSIVal, WifiTimeVal);
}
}
dataset.addSeries(series2);
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
mRenderer.addSeriesRenderer(renderer2);
dataset.addSeries(series3);
XYSeriesRenderer renderer3 = new XYSeriesRenderer();
mRenderer.addSeriesRenderer(renderer3);
break;
case 3:
break;
-
-
-
-
-
case 10:
break;
Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Graph 1");
this.startActivity(intent); //I have tried here by this (startActivity(intent))
<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>
- 01-17-2012, 12:39 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: Creating a class that extends Activity and implements OnClickListener
@bdtuhin007
Please start your own thread for your question.
[Edit] The process is much the same as you used when you cross posted at javaprogrammingforums.comLast edited by pbrockway2; 01-17-2012 at 12:45 AM.
Similar Threads
-
Advanced extends and implements
By V1C3M4N in forum Advanced JavaReplies: 15Last Post: 11-17-2010, 01:28 PM -
Class that extends JFrame help
By javaman1 in forum New To JavaReplies: 5Last Post: 11-10-2010, 02:29 AM -
Adding 2 Implements to the class
By jboy in forum New To JavaReplies: 2Last Post: 10-23-2009, 05:19 AM -
[SOLVED] how to print a class that extends another class
By alpdog14 in forum New To JavaReplies: 3Last Post: 03-19-2009, 05:00 PM -
Implements MyClass extends JFrame
By coco in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 03:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks