0

My application was working fine before reading in XML objects but now I have added to the two buttons and a textview to it it's having a problem finding them.

So I added the three objects there for more control of my application and the activity class cannot find them

public class TVListingTestActivity extends Activity implements OnClickListener 
{
private static final String TAG = "myApp";

private EditText infoView;
private String result;
private String full;

public int count;

final Context context =this;

private LinkedList<Widget> aList;
private LinkedList<String> stringList;
private LinkedList<Button> buttons;

private Button forwardDay;
private Button backDay;
private TextView display;

private int dayParse= 0;
private String tvListingURL;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    stringList = new LinkedList<String>();

    infoView= (EditText) findViewById(R.id.infoView);
    tvListingURL = "http://bleb.org/tv/data/rss.php?ch=bbc1_scotland&day="+dayParse;

    forwardDay=(Button)findViewById(R.id.forwardbutton);
    backDay=(Button)findViewById(R.id.backbutton);
    display=(TextView)findViewById(R.id.displayview);

The resources seem to be showing up in the R file so I cannot understand what the problem is. Has anyone encounterd anything like this before?

package org.me.myandroidstuff;

public final class R {
public static final class array {
    public static final int shows=0x7f040000;
}
public static final class attr {
}
public static final class drawable {
    public static final int icon=0x7f020000;
}
public static final class id {
    public static final int back=0x7f060002;
    public static final int cspinner=0x7f060007;
    public static final int dialog_info=0x7f060000;
    public static final int infoView=0x7f060003;
    public static final int main=0x7f060004;
    public static final int main_page=0x7f060006;
    public static final int mainll=0x7f060005;
    public static final int reminder=0x7f060001;
}
public static final class layout {
    public static final int dialog_info=0x7f030000;
    public static final int main=0x7f030001;
    public static final int main_page=0x7f030002;
}
public static final class string {
    public static final int app_name=0x7f050001;
    public static final int hello=0x7f050000;
}
}
6
  • 1
    please replace the images with actual code. It's much easier on the eyes. Commented Apr 1, 2013 at 19:57
  • From what I can see in the images it looks ok except I don't know why the edit posted the same image twice. Anyway, I would make sure you don't have any errors in xml and try cleaning your project. And yes, please copy/paste code instead of supplying screenshots Commented Apr 1, 2013 at 20:02
  • A minor error, but should not cause the problem you are seeing. When referring to existing views, use @id/reference. @id+/reference (note the plus) is used to add a new reference. In all versions of Android I've worked with, it works even when you add the plus but, it is not in accordance with the documentation so you should fix it. Commented Apr 1, 2013 at 20:06
  • Try a clean in eclipse. Commented Apr 1, 2013 at 20:06
  • I tried a clean- the reason for the screenshots is so you can see where the errors are occuring as posting the code removes the red error lines Commented Apr 1, 2013 at 20:08

3 Answers 3

1

Delete android.R from your imports in java file.

Sign up to request clarification or add additional context in comments.

2 Comments

@algorhythm This is a very frequented mistake. Plese upvote this. So others could avoid this mistake.
Sorry I can't atm, need at least 15 rep. Can't even ask any questions until my rep is better
0

Check if the R.java contains the "main" class inside the layout class. The R.java is inside the gen folder.

1 Comment

Yeah it does, it was working fine before I made the changes, I've removed them and it's still playing up
0

The ids of the two buttons and the TextView in R.java are not the ones in your TVListingTestActivity class. Make sure they are the same in XML layout files and R.java, clean your project, then initialize properly:

For example, backDay button initialization should be changed from:

backDay = (Button)findViewById(R.id.backbutton);

to:

backDay = (Button)findViewById(R.id.back);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.