0

AndroidデベロッパーウェブサイトのFirstAppプロジェクトの2番目のステップで説明されているように表示される結果を取得するのに苦労しています:developer.android.com/training/basics/firstapp/starting-activity.html#receivetheintent

最初のインテントを作成し、他のすべてのコードをコピーしましたが、プロジェクトを実行すると、入力要素のない空白のAndroid画面が表示されます。エミュレータの外観は次のとおりです: http ://s1278.beta.photobucket.com/user/cetmrw791346/media/1_zps116f17a9.png.html

実行構成をNexusタイプで512MBのRAMを割り当てて設定したので、これがJava SDK(7.0)(JREではなくJDK)に関するインストールの問題と関係があるのか​​どうかは正確にはわかりません。 AndroidSDKである可能性があります。私はすべてを正しく設定したとかなり確信しています。私はモバイル開発者向けにEclipse(IDEだと確信しています)を使用しており、File、NewProjectから新しいAndroidアプリプロジェクトを作成しています。パッケージエクスプローラーは次のようになります:http ://s1278.beta.photobucket.com/user/cetmrw791346/media/2_zps0f2b94a2.png.html

問題をさらにトラブルシューティングする方法がわからないので、追加のサポートをいただければ幸いです。助けてくれてありがとう。

そして、ここに関連するファイルがあります:

**AndroidManifest.xml**


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.firstapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.firstapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.firstapp.DisplayMessageActivity"
            android:label="@string/title_activity_display_message"
            android:parentActivityName="com.example.firstapp.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.firstapp.MainActivity" />
        </activity>
    </application>

</manifest>

    **MainActivity.java**


    package com.example.firstapp;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.View;
    import android.widget.EditText;

    public class MainActivity extends Activity {

        public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }


        /** Called when the user clicks the Send button */
        public void sendMessage(View view) {
            Intent intent = new Intent(this, DisplayMessageActivity.class);
            EditText editText = (EditText) findViewById(R.id.edit_message);
            String message = editText.getText().toString();
            intent.putExtra(EXTRA_MESSAGE, message);
            startActivity(intent);
        }
    }

    **activity_main.xml**
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        tools:context=".MainActivity" >
      <EditText android:id="@+id/edit_message"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="@string/edit_message" />
    <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_send"
             android:onClick="sendMessage" />

    </LinearLayout>


    **strings.xml**


    <?xml version="1.0" encoding="utf-8"?>
    <resources>

        <string name="app_name">My First App</string>
        <string name="edit_message">Enter a message</string>
        <string name="button_send">Send</string>
        <string name="menu_settings">Settings</string>
        <string name="title_activity_main">MainActivity</string>
        <string name="title_activity_display_message">DisplayMessageActivity</string>
        <string name="action_settings">Settings</string>
        <string name="hello_world">Hello world!</string>

    </resources>

    activity_display_message.xml
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".DisplayMessageActivity" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />

    </RelativeLayout>


    **DisplayMessageActivity.java**


    package com.example.firstapp;

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.support.v4.app.NavUtils;
    import android.annotation.TargetApi;
    import android.os.Build;

    public class DisplayMessageActivity extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_display_message);
            // Show the Up button in the action bar.
            setupActionBar();
        }

        /**
        * Set up the {@link android.app.ActionBar}, if the API is available.
        */
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        private void setupActionBar() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                getActionBar().setDisplayHomeAsUpEnabled(true);
            }
        }


        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
            case android.R.id.home:
                // This ID represents the Home or Up button. In the case of this
                // activity, the Up button is shown. Use NavUtils to allow users
                // to navigate up one level in the application structure. For
                // more details, see the Navigation pattern on Android Design:
                //
                // http://developer.android.com/design/patterns/navigation.html#up-vs-back
                //
                NavUtils.navigateUpFromSameTask(this);
                return true;
            }
            return super.onOptionsItemSelected(item);
        }

    }
4

4 に答える 4

1

アプリをまだ実行していないようです (エミュレーターはまだ起動中です)。

私はJavaとAndroidの両方にまったく慣れていません(オンラインコースを受講して数週間しか経っていません)が、エミュレーターが非常に遅いことがわかったので、実際のデバイスを接続してアプリの実行に使用することをお勧めします. .

Galaxy S2 を Linux に接続して [RUN] をクリックすると、Eclipse を使用してアプリを実行できます。私がフォローしているコースの例では、アプリはわずか数秒で起動しますが、エミュレーターで実行するのは苦痛です。

それでもエミュレーターを使用する必要がある場合は、ADT で仮想デバイスのプロパティを編集し、「[X] スナップショットを使用する」フラグをオンにすることで高速化できます。このフラグを有効にすると、「仮想デバイス」を毎回「電源オフ」および「電源オン」する必要がなくなります。仮想デバイスを閉じると、現在の状態がスナップショットとしてディスクに保存され、再度実行すると、起動するのを待つ必要はありません。スナップショットが使用され、仮想デバイスが非常に高速に起動します。

于 2013-03-11T13:45:27.900 に答える
1

エミュレータがまだ起動していないようです。起動してホーム画面が表示されるまで待ってから、アプリを実行してください。

于 2013-03-11T13:15:08.120 に答える
1

いくつかのポイント:

  1. アプリを実際に起動させていないようです。投稿した最初の画面は、エミュレータの「ブート」画面です
  2. Eclipse でデバッグ パースペクティブに切り替えてみましたか? 下部に、Eclipse が実際に何を行っているかが表示されます。もう少し詳細を表示するには、コンソール ビューに切り替えたり、logcat を表示したりする必要がありますが、これは実際に作業に役立つはずです。
  3. エミュレーターの起動に問題がある場合は、それ自体でテストできます。(たとえば) Eclipse の上部バーにある 2 つの Android アイコンの 2 番目を選択するオプションがあります。「Android Virtual Device Manager」と表示されているはずです。それを選択すると、構成済みのエミュレーターが表示されますが、新しいものも構成できます。それらのいずれかを事前に開始して、それらがどのように機能するかを確認できます。
于 2013-03-11T13:16:10.813 に答える
0

実際のデバイスで同様の問題が発生しました。helloworld でうまく機能した後、コードにいくつかの変更 (UI の構築) を行った後も、HelloWorld を表示し続けます。それは私が解決するつもりのないスタックです...

于 2013-03-28T10:15:56.433 に答える