i've just started android programming and i can't put the image into MainActivity.java. I get an error.
Multiple markers at this line
-Syntax error, insert "... VariableDeclaratorId" to complete
FormalParameterList
- Syntax error, insert "... VariableDeclaratorId" to complete
FormalParameterList
- Syntax error on token "setImageResource", Identifier expected after
this token
Java code is (i get an error on 2nd line)
.....
final ImageView image = (ImageView) findViewById(R.id.ImageView1);
image.setImageResource(R.drawable.ic_launcher);
}
Android is
<ImageView
android:id="@+id/ImageView1"
android:contentDescription="@string/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
Help me please, i really can't understand what is that, i've been stucking on it for 2 weeks!
I guess ic_launcher is not in drawable folder, but in mipmap. So you need to use R.mipmap.ic_launcher in code and @mipmap/ic_launcher in xml
Why have you declared ImageView variable as final
? If you declared a variable as final
, it can never be changed after it has been defined . So, try to remove final
keyword of image declaration.
You could also remove android:src
declaration from your layout, instead of removing final
keyword.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.