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

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

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

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

Android Studio

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

Q&A

解決済

1回答

6964閲覧

AndroidStudioでエラーが出るのですが、componentTreeのせいなのでしょうか?

edoooooo

総合スコア476

Java

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

Android Studio

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

1グッド

0クリップ

投稿2016/05/11 09:32

編集2016/05/12 15:18

イメージ説明
このactivity_chat.xmlのなかに本では
Device Screen の下に
RelativeLayout となっているのですが、どうすれば作ることができるのでしょうか?

またもう一つのcontent_chat.xmlのなかになぜか
このようにRelativeLayoutが入っています。
イメージ説明

AndroidStudioの仕組みがわかりません。
AndroidStudioのインストールする内容を選択する所から本と表示の形態が違いインストールに不備があったのでしょうか?

使用している参考書はAndroid Studioで始めるAndroidアプリ開発の教科書 AndroidStudio 1.3対応
という本で、2015年発行の本です。サンプルコードを写したつもりなのですが、エラーが多く
componentTreeの構造に問題があるのではないかと考えています。

java

1Error:(2) Error parsing XML: XML or text declaration not at start of entity 2Error:Execution failed for task ':chatapplication:processDebugResources'. 3> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/taichi/Library/Android/sdk/build-tools/23.0.3/aapt'' finished with non-zero exit value 1

エラーはこのようなものです。
どうぞよろしくお願いします。

activity_chat.xml

xml

1<?xml version="1.0" encoding="utf-8"?> 2<android.support.design.widget.CoordinatorLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 6 android:layout_height="match_parent" android:fitsSystemWindows="true" 7 tools:context=".ChatActivity"> 8 9 <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" 10 android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> 11 12 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" 13 android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" 14 android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> 15 16 </android.support.design.widget.AppBarLayout> 17 18 <include layout="@layout/content_chat" /> 19 20 <android.support.design.widget.FloatingActionButton android:id="@+id/fab" 21 android:layout_width="wrap_content" android:layout_height="wrap_content" 22 android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" 23 android:src="@android:drawable/ic_dialog_email" /> 24 25</android.support.design.widget.CoordinatorLayout> 26

content_chat.xml

xml

1 2<?xml version="1.0" encoding="utf-8"?> 3<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:tools="http://schemas.android.com/tools" 5 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 android:paddingLeft="@dimen/activity_horizontal_margin" 9 android:paddingRight="@dimen/activity_horizontal_margin" 10 android:paddingTop="@dimen/activity_vertical_margin" 11 android:paddingBottom="@dimen/activity_vertical_margin" 12 13 tools:context=".ChatActivity"> 14 15 16 17 <EditText 18 android:layout_width="wrap_content" 19 android:layout_height="wrap_content" 20 android:id="@+id/input_message" 21 android:layout_alignParentTop="true" 22 android:layout_alignParentLeft="true" 23 android:layout_alignParentStart="true" 24 android:layout_toLeftOf="@+id/send_message" 25 android:layout_toStartOf="@+id/send_message" /> 26 27 <Button 28 android:layout_width="wrap_content" 29 android:layout_height="wrap_content" 30 android:text="SEND" 31 android:id="@+id/send_message" 32 android:layout_alignParentTop="true" 33 android:layout_alignParentRight="true" 34 android:layout_alignParentEnd="true" /> 35 36 <LinearLayout 37 android:orientation="vertical" 38 android:layout_width="fill_parent" 39 android:layout_height="fill_parent" 40 android:layout_below="@+id/input_message" 41 android:layout_alignParentLeft="true" 42 android:layout_alignParentStart="true" 43 android:id="@+id/message_log"> 44 45 <TextView 46 android:layout_width="wrap_content" 47 android:layout_height="wrap_content" 48 android:text="こんにちは" 49 android:id="@+id/cpu_message" 50 android:layout_gravity="start"/> 51 52 <TextView 53 android:layout_width="wrap_content" 54 android:layout_height="wrap_content" 55 android:text="" 56 android:id="@+id/user_message" 57 android:layout_gravity="end" /> 58 </LinearLayout> 59 60</RelativeLayout> 61 62

manifestfileです。

xml

1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="jp.study.example37" > 4 5 <application 6 android:allowBackup="true" 7 android:icon="@mipmap/ic_launcher" 8 android:label="@string/app_name" 9 android:supportsRtl="true" 10 android:theme="@style/AppTheme" > 11 <activity 12 android:name=".MainActivity" 13 android:label="@string/app_name" 14 android:theme="@style/AppTheme.NoActionBar" > 15 <intent-filter> 16 <action android:name="android.intent.action.MAIN" /> 17 18 <category android:name="android.intent.category.LAUNCHER" /> 19 </intent-filter> 20 </activity> 21 </application> 22 23</manifest> 24 25![イメージ説明](f13e09cc8f287780da7436b2ec9e553a.png) 26どうぞよろしくお願いします。
ikuwow👍を押しています

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

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

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

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

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

guest

回答1

0

ベストアンサー

AndroidStudioは盛んにアップデートしています。最新のものは2.xまでバージョンアップしています。
あなたがどのバージョンでやっているかは知りませんが、バージョンが違うと見た目が大きく異なることがあります。
また、コードについても環境が異なれば動かなくなることは当然あります。

書籍は写経ではなく、何がしたくてこのコードを書いているのかを理解すべきでしょう。

activity_chat.xmlとcontent_chat.xmlを質問に追記してください。

投稿2016/05/11 10:06

yona

総合スコア18155

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

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

edoooooo

2016/05/11 10:09

ありがとうございます。 ついかします。
yona

2016/05/11 10:31

おかしいところは無いですね。 次はマニフェストファイルを追加してください。
edoooooo

2016/05/11 10:34

追加いたしました。どうぞよろしくお願いします。
yona

2016/05/11 10:47

問題なさそうですね。 仕方ないのでとりあえずbuildversionを23に下げまでみましょう。 ちなみに参考書でのバージョンは何でしょうか。
edoooooo

2016/05/11 14:55

ありがとうございます。AndroidStudio 1.3対応と書いてあるのですがこれではないですか?builversionとはどこをみればいいのでしょうか?申し訳ありません。
yona

2016/05/11 15:57

あなたのAndroidStudioがどのような環境かは知りませんが、1.3対応というのは、それ以外、特にそれ以上のバージョンについては知らないよって意味ですよ。 また、buildversionはAndroidStudioとは直接的に関係ありません。gradleファイルに記載されています。 コメントで何かわからなければ自分で調べてからコメントを返さないといつまでも解決しませんよ?
edoooooo

2016/05/11 16:16

すみません、garadleファイルには、 buildToolsVersion "23.0.3" をbuildToolsVersion "23"のようにして実行したところ Error:failed to find Build Tools revision 23.0.0 <a href="install.build.tools">Install Build Tools 23.0.0 and sync project</a> と出てきて、調べてみたところ、version23を見つけるのに失敗したようです。 またprojectに同期しようとしているという英文でした。 buildversionというものはありませんでした。
yona

2016/05/12 00:07

buildToolsVersionの誤りでしたね。 無いならインストールしてください。
edoooooo

2016/05/12 03:29

ありがとうございます。やってみます。
edoooooo

2016/05/12 03:55

buildToolsVersion "23.0.0" インストールしました。 Massages Gradle Buildのエラーは上記に表示したえらーと変わりませんでした。 どうぞよろしくお願いします。
yona

2016/05/12 04:01

再起動してGradleを同期しましたか?
edoooooo

2016/05/12 09:08

していませんでした。再起動をしてupdateをして、buildglidleの数字を23.0.0に変更して実行したのですが、 Error:Execution failed for task ':chatapplication:processDebugResources'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/taichi/Library/Android/sdk/build-tools/23.0.0/aapt'' finished with non-zero exit value 1 このようにupdateを終了しましたと出てきました。 エラーが出たため同期を行おうと思い multiDexEnabled trueをbuild.gradleのdefaultConfig{}に書いたところ、なぜか build.gradleの中身が // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } とだいぶ変わってしまいました。
yona

2016/05/12 09:22

AndroidStudioの右下にあるGradleConsoleに何かメッセージは出ていませんか?
edoooooo

2016/05/12 11:34

GradleConsoleの途中からなのですが、 AGPBI: {"kind":"error","text":"Error parsing XML: XML or text declaration not at start of entity","sources":[{"file":"/Users/taichi/AndroidStudioProjects/example37/chatapplication/src/main/res/layout/content_chat.xml","position":{"startLine":1}}],"original":""} FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':chatapplication:processDebugResources'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/taichi/Library/Android/sdk/build-tools/23.0.0/aapt'' finished with non-zero exit value 1 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 2.034 secs と出ています。 XMLにエラーがあり宣言がなくスタートされています。 実行を間違えていて失敗しています。 と呼んだのですが、どうぞよろしくお願いします。
yona

2016/05/12 13:52

先頭行に空行がありませんか? これを消してください。
edoooooo

2016/05/12 14:51 編集

消した後にAndroidStudioを開き直したのですが、先ほど追加したコードが薄灰色になり、 カーソルを合わせるとNamespace declaration is newver userd more となります。 どうぞよろしくお願いします。
yona

2016/05/12 14:58

何か修正したら再度ビルドして、実行してください。無意味なやりとりが増えます。
edoooooo

2016/05/12 15:09

申し訳ありませんでした。 エラーが変わりました。 mMessageLog=(LinearLayout)findViewById(R.id.message_log);//入力履歴を表示するレイアウトこのmessage_logがカーソルを合わせるとCannot resolve symbol message_logとなります。MassageGradleBuildのエラーメッセージは、 シンボルを見つけられませんとなり、message_logが指定されています。 また非推奨のAPIを使用またはオーバーライドしています。となります。 スクリーンショットを先ほどのものと取り替えます。 どうぞよろしくお願いします。
yona

2016/05/12 15:15

本質問の主原因は解決したようです。 まとめると、XMLの先頭行に空行を入れてはいけないということですね。 エラーが変わるたびに調べていましたか?「どうぞよろしくお願いします」と丸投げするのではなく、回答やコメントから自分なりに調べ、考え、コメントすべきです。 最新のエラーは単純なものなので調べてみてください。
edoooooo

2016/05/12 15:20

ありがとうございました。調べて力をつけていきます。 しっかりと検索をしてから質問をするようにします。 ありがとうございました。
yona

2016/05/12 15:24

エラーログを読む力は重要なので、たくさん、調べると開発が楽になりますよ。
edoooooo

2016/05/17 07:56

ありがとうございます。少しずつ力をつけていきたいと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問