0

我正在开发一个将使用图像的 Android 应用程序,因此我正在努力抓取图像并显示它。虽然当我输入时setContentView(R.layout.main);它告诉我main不存在但提供放入布局文件或R.java. 尝试将其放入文件并保存R.java文件时告诉我它已将其恢复为原始用途,这是为什么呢?

4

2 回答 2

2

From your comments you said you have activity_main.xml and not main.xml

So change to

setContentView(R.layout.activity_main);

ALso if you have imported R.java remove the same. Make sure there are no errors in your resource files. Clean and build.

If you have a imageview in activity_main.xml with id gimg1 then

  ImageView iv = (ImageView) findViewById(R.id.gimg1);

and import

  import android.widget.ImageView;

Its the same to initialize if you have others view's in your xml

于 2013-09-26T14:43:04.320 回答
1

R.java文件是自动生成的,不能编辑。在您的情况下,通过 tyr 清理您的项目Project->Clean

于 2013-09-26T14:39:55.507 回答