1. Download our Official Android App: Forums for Android!

Apps NullPointer

Discussion in 'Android Development' started by sehudson, Jun 5, 2011.

  1. sehudson

    sehudson Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    Feb 2, 2011

    Feb 2, 2011
    17
    0
    15
    I am trying to start an activity from within my listener. Once the listener is triggered, I keep getting a nullPointer on startActivity(i). The Activity exists for sure, any ideas? My println statements give me exactly what I expect, but for some reason this blows up on startActivity(i).
    Code (Text):
    1.  
    2. package com.Watch;
    3.  
    4. import android.app.Activity;
    5. import android.content.Intent;
    6. import android.database.Cursor;
    7. import android.view.View;
    8. import android.view.View.OnClickListener;
    9.  
    10. public class TRListener extends Activity implements OnClickListener{
    11.     int rowNum;
    12.     Cursor values;
    13.    
    14.     public static String nameTransfer;
    15.     public static String dateTransfer;
    16.     public static String amtValTransfer;
    17.  
    18.    
    19.     public TRListener(int rowNumber){
    20.         System.out.println("setting row to "+rowNumber);
    21.         rowNum = rowNumber;
    22.        
    23.     }
    24.  
    25.  
    26.     @Override
    27.     public void onClick(View v) {
    28.         System.out.println("Listener Activated: moving to row: "+rowNum);
    29.     //Get the Database Values
    30.     values = ExpenseAct.results;
    31.     //Move to the Specified row
    32.     values.moveToPosition(rowNum);
    33.  
    34.  
    35.     String name = values.getString(0);
    36.     String date = values.getString(1);
    37.     String amt = values.getString(3);
    38.    
    39.     nameTransfer = new String(name);
    40.     dateTransfer = new String(date);
    41.     amtValTransfer = new String(amt);
    42.     System.out.println("Name: "+nameTransfer);
    43.     System.out.println("Date: "+dateTransfer);
    44.     System.out.println("Amt: "+amtValTransfer);
    45.    
    46.    
    47.     Intent i = new Intent();
    48.     i.setClassName("com.Watch",
    49.                    "com.Watch.mac2");
    50.     startActivity(i);
    51.  
    52.        
    53.     }
    54.  
    55. }
     

    Advertisement

  2. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    Is the Activity you are trying to start added in AndroidManifest.xml?
     
  3. pietjuhhh1990

    pietjuhhh1990 Well-Known Member
    Rank:
    None
    Points:
    38
    Posts:
    235
    Joined:
    Feb 21, 2011

    Feb 21, 2011
    235
    22
    38
    App/web development
    Netherlands
    Intent i = new Intent((currentactivity).this, (nwactivity).class);
    (currentactivity).this.startActivity(i);
     

Share This Page

Loading...