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

Apps Problem with Inner Classes

Discussion in 'Android Development' started by andravis, Apr 14, 2010.

  1. andravis

    andravis Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    2
    Joined:
    Apr 14, 2010

    Apr 14, 2010
    2
    0
    25
    hey everyone,

    i'm pretty new to programming for android, i'm using eclipse as my ide, and i'm having difficulty with anonymous inner classes. for instance, i'll simply copy/paste example code from android.com or write my own code and everything goes fine until i reach an anonymous class.

    for example, i've copied/pasted the following from android.com:

    lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
    int position, long id) {
    // When clicked, show a toast with the TextView text
    Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
    Toast.LENGTH_SHORT).show();
    }
    });

    and the error occurs with OnItemClickListener() { ... on the first line. the problem description in eclipse reads, "OnItemClickListener cannot be resolved to a type."

    any suggestions?

    thanks everyone,

    andrew
     

    Advertisement

  2. dmitriyk

    dmitriyk Member
    Rank:
    None
    Points:
    18
    Posts:
    44
    Joined:
    Apr 17, 2010

    Apr 17, 2010
    44
    10
    18
    Software Developer
    Salt Lake City, UT
    The problem isn't with the inner class per-se; the problem is that Java can't find OnItemClickListener. Make sure you either import it at the top of the file with "import android.widget.AdapterView.OnItemClickListener;" or define your inner class as "...new android.widget.AdapterView.OnItemClickListener()..."
     
  3. shelarsheetal

    shelarsheetal Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Aug 25, 2011

    Aug 25, 2011
    3
    0
    5
    main cannot b resolve to the type
     
  4. shelarsheetal

    shelarsheetal Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Aug 25, 2011

    Aug 25, 2011
    3
    0
    5
    what is the solution to the above error sentence?
     
  5. shelarsheetal

    shelarsheetal Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Aug 25, 2011

    Aug 25, 2011
    3
    0
    5
    Hi I'm trying some of the Android applications for practice purpose, but i'm facing a lof of problems while development, the most common problem is- id/main cannot b resolve to the type, can i get a proper suggestion for my query. Also m working on Linux n while runnig my application i see that it takes purely 5mins for a emulator to show the output, so i just wanted to know that is it usual with Linux???
     

Share This Page

Loading...