For the life of me I can't run this on my android emulator;I'm new to this but I thought getting an image output should be easy!
I get these two errors in Eclipse(Android plug-in)IDE
1.findViewbyId cannot be resolved
2.the method setImageView(String) is undefined for the type catwalk
Please see the code below
package com.marueli.catwalk;
import android.app.Activity;
import android.os开发者_StackOverflow中文版.Bundle;
import android.widget.ImageView;
public class Catwalk extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView(findViewById);
setImageView("R.drawable.Cat.PNG");
setContentView(R.layout.main);
}
}
It is my first code after going through several tutorials.Thank you.
Regards, Eli.
findViewById is a method and R.drawable.cat is a variable.
try.
package com.marueli.catwalk;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class Catwalk extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imageView = (ImageView) this.findViewById(R.id.image_view_id);
imageView.setImageResource(R.drawable.cat);
}
}
image_view_id is the android:id of the image view in your main.xml file and i am assuming that in your drawable directory you have a file name cat.png.
精彩评论