Results 1 to 5 of 5
  1. #1
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default 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?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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.

  3. #3
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default

    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)

  4. #4
    bdtuhin007 is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default 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))
    <<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default 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.com
    Last edited by pbrockway2; 01-17-2012 at 12:45 AM.

Similar Threads

  1. Advanced extends and implements
    By V1C3M4N in forum Advanced Java
    Replies: 15
    Last Post: 11-17-2010, 01:28 PM
  2. Class that extends JFrame help
    By javaman1 in forum New To Java
    Replies: 5
    Last Post: 11-10-2010, 02:29 AM
  3. Adding 2 Implements to the class
    By jboy in forum New To Java
    Replies: 2
    Last Post: 10-23-2009, 05:19 AM
  4. Replies: 3
    Last Post: 03-19-2009, 05:00 PM
  5. Implements MyClass extends JFrame
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 03:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •