0

I just want to set a text in a textView from strings.xml using java code but I just can't, eclipse gives me this error: "textView1 cannot be resolved" and "textView2 cannot be resolved".

Here is mi activity:

package com.example.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;

public class Descripcion extends Activity{

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.descripcion);

    Intent i = getIntent();

    int position = i.getExtras().getInt("id");
    ImageAdapter imageAdapter = new ImageAdapter(this);

    switch (position){
    case 0:

    ImageView imageView0 = (ImageView) findViewById(R.id.full_image_view);
    imageView0.setImageResource(imageAdapter.mThumbIds[position]);

    textView1.setText(this,getString(R.string.case0));
    textView2.setText(this,getString(R.string.case0b));

    break;

    case 1:

    ImageView imageView1 = (ImageView) findViewById(R.id.full_image_view);
    imageView1.setImageResource(imageAdapter.mThumbIds[position]);

    textView1.setText(this,getString(R.string.case1));
    textView2.setText(this,getString(R.string.case0b));

    break;  
    }
}
}

I've beeing looking for a solution for about 3 hours but I can't fid it.

0

5 Answers 5

3

I can't see where you are declaring your TextView's, such as:

TextView textView1 = (TextView)findViewById(R.id.textView1);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! I'm just doing my first app for android, in objective-c you have to define labels and buttons in other file, I forgot that in java it's diferent =D
No worries, we've all been there. I went from PHP to Java, talk about a learning curve :)
1

1) You didn't define TextView

2) You didn't do findViewById to get corresponding TextView

How to do that?

Your code itself has clues on how to do that, example:

ImageView imageView1 = (ImageView) findViewById(R.id.full_image_view);

Here you defined ImageView and pointed it to R.id.full_image_view defined in layout.xml

like this you need to get TextView, example:

TextView textView1 = (TextView)findViewById(R.id.textView1);

3 Comments

I've define my TextView but now I have this error: The method setText(CharSequence, TextView.BufferType) in the type TextView is not applicable for the arguments (activity, String) activity.java /aplicacion/src/com/example/memepedia line 31 Java Problem
Why this as first parameter? shouldn't it be just setText(getString(R.string.case1))?
Thanks a lot! I'm just doing my first app for android, in objective-c you have to define labels and buttons in other file, I forgot that in java it's diferent =D
0

You forgot to define the variables textView1 and textView2. Besides that you need to obtain a reference to them using findViewById. Weird part is that you did this for imageView1 and forgot to do it for the TextViews.

Add the following piece of code below etContentView(R.layout.descripcion):

TextView textView1 = (TextView) findViewById(<<-- the id of textView1 -->>); TextView textView1 = (TextView) findViewById(<<-- the id of textView2 -->>);

1 Comment

Thanks a lot! I'm just doing my first app for android, in objective-c you have to define labels and buttons in other file, I forgot that in java it's diferent =D
0

That's because textView1 and textView2 aren't defined....

You see what you do with the ImageView?

ImageView imageView0 = (ImageView) findViewById(R.id.full_image_view);

You have to apply the same concept to the text views.

TextView textView1 = (TextView) findViewById(R.id.id_of_text_view_1);
TextView textView2 = (TextView) findViewById(R.id.id_of_text_view_2);

Then you can perform operations on that text view, such as setting the text!

1 Comment

Thanks a lot! I'm just doing my first app for android, in objective-c you have to define labels and buttons in other file, I forgot that in java it's diferent =D
0

define your textviews as you did your imageview.

you can use

TextView textView1 = (TextView)findViewById(R.id.textView1);
TextView textView2 = (TextView)findViewById(R.id.textView2);

where

R.id.textView1

is the id of your textview1 in your xml layout

R.id.textVie2

is the id of your textview2 in your xml layout

1 Comment

Thanks a lot! I'm just doing my first app for android, in objective-c you have to define labels and buttons in other file, I forgot that in java it's diferent =D

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.