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

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

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

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

Java

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

Android

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

Android Studio

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

Q&A

0回答

1009閲覧

エラーの解消の仕方がわかりません

Wisteria314159

総合スコア10

XML

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

Java

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

Android

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

Android Studio

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

0グッド

0クリップ

投稿2019/03/10 05:58

編集2022/01/12 10:55

実現したいこと

androidのアプリで自分で設定した範囲,好きな数だけランダムに表示されるソフトを作っています。サイトを参考にしながら頑張ったのですが上手くいきませんでした。詳しく教えていただけると嬉しいです。

該当のソースコード

java

1package com.e.random; 2 3import android.support.v7.app.AppCompatActivity; 4import android.os.Bundle; 5import android.text.SpannableStringBuilder; 6import android.view.View; 7import android.widget.Button; 8import android.widget.EditText; 9import android.widget.TextView; 10 11import java.util.ArrayList; 12import java.util.Collections; 13 14public class MainActivity extends AppCompatActivity { 15 private boolean flag = false; 16 17 @Override 18 protected void onCreate(Bundle savedInstanceState) { 19 super.onCreate(savedInstanceState); 20 setContentView(R.layout.activity_main); 21 22 TextView textView1 = findViewById(R.id.textView1); 23 textView1.setText("Minimum Number"); 24 25 TextView textView2 = findViewById(R.id.textView2); 26 textView2.setText("Maximum Number"); 27 28 TextView textView3 = findViewById(R.id.textView3); 29 textView3.setText("Extraction Number"); 30 31 EditText editText1 = findViewById(R.id.editText1); 32 SpannableStringBuilder sb1 = (SpannableStringBuilder) editText1.getText(); 33 final String str1 = sb1.toString(); 34 35 EditText editText2 = findViewById(R.id.editText2); 36 SpannableStringBuilder sb2 = (SpannableStringBuilder) editText2.getText(); 37 final String str2 = sb2.toString(); 38 39 EditText editText3 = findViewById(R.id.editText3); 40 SpannableStringBuilder sb3 = (SpannableStringBuilder) editText3.getText(); 41 final String str3 = sb3.toString(); 42 final int z = Integer.parseInt(str3); 43 44 Button button = findViewById(R.id.GENERATE); 45 button.setOnClickListener(new View.OnClickListener() { 46 @Override 47 public void onClick(View v) { 48 if (flag){ 49 ArrayList<Integer> list = new ArrayList<>(); 50 for (int i = Integer.parseInt(str1);i > Integer.parseInt(str2);i++) { 51 list.add(i); 52 } 53 Collections.shuffle(list); 54 55 int[] answer = new int[z]; 56 for (int i = 0; i < answer.length; i++) { 57 answer[i] = list.get(i); 58 } 59 TextView textView4 = findViewById(R.id.textView4); 60 textView4.setText("" + answer); 61 } 62 } 63 }); 64 65 } 66}

↑MainActivity.java

xml

1<?xml version="1.0" encoding="utf-8"?> 2<android.support.constraint.ConstraintLayout 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 android:background="#000000" 8 tools:context=".MainActivity"> 9 10 <TextView 11 android:id="@+id/textView1" 12 android:layout_width="136dp" 13 android:layout_height="23dp" 14 android:layout_marginStart="32dp" 15 android:layout_marginTop="128dp" 16 android:textColor="#ffffff" 17 android:textSize="7pt" 18 app:layout_constraintStart_toStartOf="parent" 19 app:layout_constraintTop_toTopOf="parent" /> 20 21 <TextView 22 android:id="@+id/textView2" 23 android:layout_width="118dp" 24 android:layout_height="23dp" 25 android:layout_marginStart="32dp" 26 android:text="Maximum Number" 27 android:textColor="#ffffff" 28 android:textSize="7pt" 29 app:layout_constraintStart_toStartOf="parent" 30 tools:layout_editor_absoluteY="183dp" /> 31 32 <TextView 33 android:id="@+id/textView3" 34 android:layout_width="wrap_content" 35 android:layout_height="wrap_content" 36 android:layout_marginStart="32dp" 37 android:layout_marginEnd="88dp" 38 android:text="Extraction Number" 39 android:textColor="#ffffff" 40 android:textSize="7pt" 41 app:layout_constraintEnd_toStartOf="@+id/editText3" 42 app:layout_constraintStart_toStartOf="parent" 43 tools:layout_editor_absoluteY="238dp" /> 44 45 <EditText 46 android:id="@+id/editText1" 47 android:layout_width="120dp" 48 android:layout_height="32dp" 49 android:layout_marginEnd="32dp" 50 android:background="#888888" 51 android:ems="10" 52 android:inputType="number" 53 android:singleLine="false" 54 android:text=" Type here" 55 android:textColor="#ffffff" 56 app:layout_constraintEnd_toEndOf="parent" 57 tools:layout_editor_absoluteY="117dp" /> 58 59 <EditText 60 android:id="@+id/editText2" 61 android:layout_width="120dp" 62 android:layout_height="32dp" 63 android:layout_marginEnd="32dp" 64 android:background="#888888" 65 android:ems="10" 66 android:inputType="number" 67 android:text=" Type here" 68 android:textColor="#ffffff" 69 app:layout_constraintEnd_toEndOf="parent" 70 tools:layout_editor_absoluteY="174dp" /> 71 72 <EditText 73 android:id="@+id/editText3" 74 android:layout_width="120dp" 75 android:layout_height="32dp" 76 android:layout_marginEnd="32dp" 77 android:background="#888888" 78 android:ems="10" 79 android:inputType="number" 80 android:text=" Type here" 81 android:textColor="#ffffff" 82 app:layout_constraintEnd_toEndOf="parent" 83 tools:layout_editor_absoluteY="228dp" /> 84 85 <Button 86 android:id="@+id/GENERATE" 87 style="@style/Widget.AppCompat.Button.Colored" 88 android:layout_width="wrap_content" 89 android:layout_height="wrap_content" 90 android:layout_marginStart="161dp" 91 android:layout_marginEnd="148dp" 92 android:background="@drawable/button_state" 93 android:text=" ⚠ GENERATEE ⚠ " 94 app:layout_constraintEnd_toEndOf="parent" 95 app:layout_constraintHorizontal_bias="1.0" 96 app:layout_constraintStart_toStartOf="parent" 97 tools:layout_editor_absoluteY="299dp" /> 98 99 <TextView 100 android:id="@+id/textView4" 101 android:layout_width="0dp" 102 android:layout_height="wrap_content" 103 android:layout_marginStart="32dp" 104 android:layout_marginTop="24dp" 105 android:layout_marginEnd="32dp" 106 android:layout_marginBottom="32dp" 107 android:text="" 108 android:textColor="#ffffff" 109 android:textSize="12pt" 110 app:layout_constraintBottom_toBottomOf="parent" 111 app:layout_constraintEnd_toEndOf="parent" 112 app:layout_constraintStart_toStartOf="parent" 113 app:layout_constraintTop_toBottomOf="@+id/GENERATE" /> 114 115 <android.support.constraint.Guideline 116 android:id="@+id/guideline" 117 android:layout_width="wrap_content" 118 android:layout_height="wrap_content" 119 android:orientation="vertical" 120 app:layout_constraintGuide_begin="20dp" /> 121 122</android.support.constraint.ConstraintLayout> 123```↑layout 124 125 126### 補足情報(FW/ツールのバージョンなど) 127 128Android Studio

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

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

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

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

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

退会済みユーザー

退会済みユーザー

2019/03/10 06:26

エラーメッセージを貼らないというのは論外なので必ず提示して下さい。
jimbe

2019/03/10 14:18

何が上手くいかなかったのでしょう. コンパイルエラーなのか, 実行時に例外が発生しているのか, 動作が Wisteria314159 さんの想像と違っていたのかさえ, こちらには分かりかねます. 何かのメッセージが出たのでしたら, そしてそれがエラーなのかが分からないのでしたら, まずそちらが分かるように成られますよう, お調べください. エラーメッセージをご理解戴いた上でそれが示す問題を解決するようにしなければ, これからも同じことの繰り返しになってしまうものと思います.
BeatStar

2019/03/11 03:55

>> 頑張ったのですが上手くいきませんでした。 本当でしょうか? エラーメッセージは確認しましたか? 今の質問者さんの質問では取扱説明書を読まずに適当にやって「動きません」と言うようなものかと。 エラーが出たのならそのエラーメッセージを載せましょう。 エスパーじゃないのですから、回答者はわかりませんよ。 コード上の問題ってこともありますが、 C言語とかだとリンクしていないことが原因だったり、 Javaとかでも、ファイルがない系の例外のことを言っているのかもしれない。 わかりませんから、メッセージぐらいは載せましょうよ。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問