Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Data, classes and linking the two

Data, classes and linking the two

Data, classes and linking the two


I am new to Eclipse programming and have a question. I have a main.xml which has a number of textViews and other information. I have a menu on which one button is "Save to PDF". When the button is tapped I need to get the textViews and a canvas image into a PDF.

I have worked out most of this, except that I cannot get the information from the form. If I try and call info from R.id.textView4 it complains of retrieving static code from a non-static field.

I have tried several things, including putting the PDF code into a separate class and using an intent, but have made no progress there either.

Could someone point me to a tutorial on calling class files and retrieving information from main.xml, or show me a simple code snippet of getting the data if putting the code in app.java?

RE: Data, classes and linking the two

Thought I would post the code I am using. Now getting no error but also the textView4 data is not pulled in. (textView4 is a textview with autocomplete):

       public boolean onOptionsItemSelected(MenuItem item) {
           switch (item.getItemId()) {
         case R.id.SavetoPDF:
             //save to PDF
             Toast.makeText(this, "Generating PDF", Toast.LENGTH_SHORT).show();
             try {
                 Document document = new Document();
                 PdfWriter.getInstance(document, new FileOutputStream(FILE));
             } catch (Exception e) {
             return true;

private void addTitlePage(Document document)
            throws DocumentException {
        TextView clName = (TextView) findViewById(R.id.textView4);

        Paragraph preface = new Paragraph();
        // add one empty line
        addEmptyLine(preface, 1);
        // header
        preface.add(new Paragraph("Timesheet", catFont));

        addEmptyLine(preface, 1);
        preface.add(new Paragraph(
                "Customer Details: ",
        addEmptyLine(preface, 1);

    preface.add(new Paragraph(
                (String) clName.getText().toString(),
        preface.add(new Paragraph(
                "This is where the address will go: ",

        // Start a new page

RE: Data, classes and linking the two

Figured it out:

String ETValue = ((TextView) findViewById(R.id.autocomplete_client)).getText().toString();

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close