В настоящее время я пытаюсь создать базовое приложение для Android и пытаюсь обернуть голову вокруг некоторых сбоев.Android-приложение продолжает сбой с чем-то связанным с id
Я пробовал комментировать и выполнять комментирование различных частей кода. Насколько я могу судить, похоже, когда у меня есть Button и TextView как во втором действии. Я пытаюсь сделать приложение для переноса текста, введенного пользователем в основном действии, на второе действие. (после нажатия кнопки). Я пытаюсь заставить второе действие иметь кнопку, которая возвращается к первому действию, а также показывать текст, который был помещен из основного действия.
Вот код для основной деятельности:
package com.example.brochura;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.widget.EditText;
import java.lang.String;
public class Main extends Activity
{
public final static String EXTRA_MESSAGE = "com.example.brochura.MESSAGE";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void sendMessage(View view)
{
Intent intent = new Intent(this, Deployed.class);
EditText editText = (EditText)findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
А вот код для второй активности:
package com.example.brochura;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.content.Intent;
import android.widget.TextView;
public class Deployed extends Activity
{
public final static String EXTRA_MESSAGE = "com.example.brochura.MESSAGE";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Button button = (Button) findViewById(R.id.return_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
finish();
}
});
Intent intent = getIntent();
String message = intent.getStringExtra(Main.EXTRA_MESSAGE);
setContentView(R.layout.deployed);
TextView textView = (TextView) findViewById(R.id.message_text);
textView.setText(message);
}
}
Катастрофа происходит, когда я пытаюсь перейти ко второму деятельности (развернутый)
Вот XML для основных и развернутых классов:
(мо in.xml)
<?xml version="1.0" encoding="utf-8"?>
<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"
>
<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:id="@+id/deploy_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"
/>
</LinearLayout>
(deployed.xml)
<?xml version="1.0" encoding="utf-8"?>
<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="vertical"
>
<Button
android:id="@+id/return_button"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="100dp"
android:text="Return"
/>
<TextView
android:id="@+id/message_text"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="100dp"
/>
</LinearLayout>
Спасибо заранее и я довольно новыми для развития мобильного поэтому любые указатели, которые кто-то может дать мне также будет весьма признателен.
--- UPDATE: Вот мой AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brochura"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19"
/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name=".Main"
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=".Deployed" />
</application>
</manifest>
Здесь представлен LogCat
I/ActivityManager(1180): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.brochura/.Main} from pid 1552
I/ActivityManager(1180): Start proc com.example.brochura for activity com.example.brochura/.Main: pid=2013 uid=10052 gids={50052}
I/ActivityManager(1180): Displayed com.example.brochura/.Main: +321ms
E/AndroidRuntime(2013): Process: com.example.brochura, PID: 2013
E/AndroidRuntime(2013): at com.example.brochura.Main.sendMessage(Main.java:36)
W/ActivityManager(1180): Force finishing activity com.example.brochura/.Main
W/ActivityManager(1180): Activity pause timeout for ActivityRecord{b131c5f0 u0 com.example.brochura/.Main t7 f}
W/InputDispatcher(1180): channel 'b149a920 com.example.brochura/com.example.brochura.Main (server)' ~ Consumer closed input channel or an error occurred. events=0x9
E/InputDispatcher(1180): channel 'b149a920 com.example.brochura/com.example.brochura.Main (server)' ~ Channel is unrecoverably broken and will be disposed!
I/ActivityManager(1180): Process com.example.brochura (pid 2013) has died.
W/InputDispatcher(1180): Attempted to unregister already unregistered input channel 'b149a920 com.example.brochura/com.example.brochura.Main (server)'
I/WindowState(1180): WIN DEATH: Window{b149a920 u0 com.example.brochura/com.example.brochura.Main}
Пожалуйста, пост [LogCat] (http://developer.android .com/инструменты/помощь/logcat.html)? – Skynet