質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

538閲覧

canvas 画像表示 複数

S.I

総合スコア48

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2017/10/16 07:56

画面横向き設定です。画面左側の枠内に画像を配置したいのですが、1つでは表示されるのですが2つではエラーが発生します。23行目のbmpの文字に赤線が表示されてしまいます…エラーメッセージ↓
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

MyView.java

java

1package com.example.nakahara.game; 2 3 4import android.content.Context; 5import android.graphics.Bitmap; 6import android.graphics.BitmapFactory; 7import android.graphics.Canvas; 8import android.graphics.Color; 9import android.graphics.Paint; 10import android.util.AttributeSet; 11import android.view.View; 12 13public class MyView extends View { 14 public MyView(Context context) { 15 super(context); 16 } 17 18 public MyView(Context context, AttributeSet attrs) { 19 super(context, attrs); 20 } 21 22 Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.neko5); 23 Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.house); 24 25 26 27 28 @Override 29 protected void onDraw(Canvas canvas) { 30 Paint paint = new Paint(); 31 paint.setColor(Color.argb(255, 0, 0, 0)); 32 33 paint.setStyle(Paint.Style.STROKE); 34 canvas.drawRect(50, 50, 1000, 1300, paint); 35 canvas.drawLine(367,50,367,1300,paint); 36 canvas.drawLine(683,50,683,1300,paint); 37 canvas.drawLine(50, (float) 362.5,1000, (float) 362.5,paint); 38 canvas.drawLine(50,675,1000,675,paint); 39 canvas.drawLine(50, (float) 987.5,1000, (float) 987.5,paint); 40 41 canvas.drawBitmap(bmp, 50, 980, paint); 42 canvas.drawBitmap(bmp, 500, 50, paint); 43 } 44}

activity_main.xml

java

1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context="com.example.nakahara.game.MainActivity"> 8 9 <LinearLayout 10 android:layout_width="0dp" 11 android:layout_height="match_parent" 12 android:layout_weight="1"> 13 14 <com.example.nakahara.game.MyView 15 android:id="@+id/view" 16 android:layout_width="match_parent" 17 android:layout_height="match_parent" 18 android:layout_alignParentTop="true" 19 tools:layout_editor_absoluteX="26dp" 20 tools:layout_editor_absoluteY="17dp" /> 21 22 </LinearLayout> 23 24 <LinearLayout 25 android:layout_width="0dp" 26 android:layout_height="match_parent" 27 android:layout_weight="1" 28 android:orientation="vertical"> 29 30 <LinearLayout 31 android:layout_width="match_parent" 32 android:layout_height="0dp" 33 android:layout_weight="1"> 34 35 </LinearLayout> 36 37 <LinearLayout 38 android:layout_width="match_parent" 39 android:layout_height="0dp" 40 android:layout_weight="1" 41 android:orientation="vertical"> 42 43 <LinearLayout 44 android:layout_width="match_parent" 45 android:layout_height="match_parent" 46 android:layout_weight="1" 47 android:orientation="horizontal"> 48 49 <Button 50 android:id="@+id/button1" 51 android:layout_width="wrap_content" 52 android:layout_height="wrap_content" 53 android:layout_gravity="center" 54 android:layout_weight="1" 55 android:text="うえ" 56 android:background="#98fb98"/> 57 58 <Button 59 android:id="@+id/button2" 60 android:layout_width="wrap_content" 61 android:layout_height="wrap_content" 62 android:layout_gravity="center" 63 android:layout_weight="1" 64 android:text="した" 65 android:background="#fffacd"/> 66 67 <Button 68 android:id="@+id/button3" 69 android:layout_width="wrap_content" 70 android:layout_height="wrap_content" 71 android:layout_gravity="center" 72 android:layout_weight="1" 73 android:text="ひだり" 74 android:background="#ffc0cb"/> 75 76 <Button 77 android:id="@+id/button4" 78 android:layout_width="wrap_content" 79 android:layout_height="wrap_content" 80 android:layout_gravity="center" 81 android:layout_weight="1" 82 android:text="みぎ" 83 android:background="#afeeee"/> 84 85 </LinearLayout> 86 87 <LinearLayout 88 android:layout_width="match_parent" 89 android:layout_height="match_parent" 90 android:layout_weight="1" 91 android:orientation="horizontal"> 92 93 <TextView 94 android:id="@+id/textView1" 95 android:layout_width="wrap_content" 96 android:layout_height="wrap_content" 97 android:layout_gravity="center" 98 android:layout_weight="1" 99 android:text="プログラムのながれ" /> 100 </LinearLayout> 101 102 <LinearLayout 103 android:layout_width="match_parent" 104 android:layout_height="match_parent" 105 android:layout_weight="1" 106 android:orientation="horizontal"> 107 108 <Button 109 android:id="@+id/button6" 110 android:layout_width="wrap_content" 111 android:layout_height="wrap_content" 112 android:layout_weight="1" 113 android:text="スタート" /> 114 115 <Button 116 android:id="@+id/button5" 117 android:layout_width="wrap_content" 118 android:layout_height="wrap_content" 119 android:layout_weight="1" 120 android:text="やりなおし" /> 121 </LinearLayout> 122 123 <LinearLayout 124 android:layout_width="match_parent" 125 android:layout_height="match_parent" 126 android:layout_weight="1" 127 android:orientation="horizontal"> 128 129 <TextView 130 android:id="@+id/textView" 131 android:layout_width="wrap_content" 132 android:layout_height="wrap_content" 133 android:layout_gravity="center" 134 android:layout_weight="1" 135 android:text="のこりじかん" /> 136 137 </LinearLayout> 138 </LinearLayout> 139 </LinearLayout> 140</LinearLayout> 141

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

変数名がbmpというフィールド変数が2個あります。フィールド変数に同名の変数は複数宣言できません。

投稿2017/10/16 08:13

yona

総合スコア18155

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問