java - Android 新手,我的简单取名应用程序崩溃了

标签 java android

大家好,我在学习 Android 时正在编写一个 name getter 应用程序,当它加载到模拟器中时,我被迫关闭该应用程序。我很新,所以这可能很简单。

namegetter.java

package edu.calpoly.android.lab1;
// tools
import android.app.Activity;
import android.content.Intent;
import android.content.pm.LabeledIntent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class NameGetter extends Activity implements android.view.View.OnClickListener{
    // variables
    private android.widget.EditText textEdit_Name;
    private android.widget.Button button_Submit;
    private String string_Name;
    private android.content.Intent intent_GetText;
    private android.os.Bundle bundle;
    private android.widget.TextView textView_Top;
    @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.name_getter);

        // assign local variables
        textEdit_Name = (EditText) this.findViewById(R.id.editText_Name);
        button_Submit = (Button) this.findViewById(R.id.button_Submit);
        textView_Top = (TextView) this.findViewById(R.id.LABEL1);
        button_Submit.setOnClickListener(this);

       bundle = this.getIntent().getExtras();

       bundle.getString(string_Name);
       textView_Top.setText(string_Name);


    }

    public void onClick(View v) {
        string_Name = textEdit_Name.getText().toString();
        // create intent to pass
        intent_GetText= new Intent(this, HelloWorld.class);
        // pass to hello world activity
        intent_GetText.putExtra(string_Name, textEdit_Name.getText().toString());
        // initiate 
        this.startActivity(intent_GetText);
    }
}

list .xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="edu.calpoly.android.lab1"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="12" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name="NameGetter"
                  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="HelloWorld" ></activity>

    </application>
</manifest>

最佳答案

最可能的原因是 getExtras() 返回 null。

bundle = this.getIntent().getExtras();
bundle.getString(string_Name);

如需更多帮助,我建议收集 logcat (adb logcat) 并发布实际异常。

关于java - Android 新手,我的简单取名应用程序崩溃了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6430948/

相关文章:

java - DataNucleus/Kundera 与 HBase 和 ElementCollection - 无法找到具有 null id 的对象

android - 有没有人在 Android 抽屉导航中实现可扩展列表

android - 如何在 Android 上查找最后的 BTS 信息?

java - Android:无法实例化接收器

android - 任务 ':mergeDebugResources' 执行失败。这是什么以及如何解决?

java - 线程 "main"java.lang.ClassNotFoundException : sample. Main 中的异常 - 为什么?

java - 如何使用 OpenCV matchShapes 检查两个轮廓是否匹配?

JavaVM Windows 7 64 位 - JFileChooser() 不显示对话框

java - 如何用java创建一个聊天客户端

android - ADB 卡在我的 Android 智能手机上