Java 编写提醒应用程序无法创建新对象

Java 编写提醒应用程序无法创建新对象,java,android,Java,Android,我正在编写一个应用程序来创建提醒。 该应用程序的工作原理如下- 无论何时,用户输入提醒文本并进行设置 应创建显示提醒文本的文本视图、启用/禁用提醒文本的复选框以及设置提醒警报的配置按钮 而不是单独创建所有这些对象。我想做一个提醒对象。 每当用户设置新提醒时,将创建此对象 这是我的密码。 我不知道为什么提醒对象不起作用。。应用程序只是强制关闭 package com.aditya.patange.taskscheduler; import android.app.Activity; import

我正在编写一个应用程序来创建提醒。 该应用程序的工作原理如下-

无论何时,用户输入提醒文本并进行设置

应创建显示提醒文本的文本视图、启用/禁用提醒文本的复选框以及设置提醒警报的配置按钮

而不是单独创建所有这些对象。我想做一个提醒对象。 每当用户设置新提醒时,将创建此对象

这是我的密码。 我不知道为什么提醒对象不起作用。。应用程序只是强制关闭

package com.aditya.patange.taskscheduler;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    EditText ReminderEditText;
    int MAX_REMINDERS = 20;
    int TEXT_SIZE = 20;
    TextView[] textviews; 
    CheckBox[] checkboxes;
    LinearLayout Llayout;
    LayoutParams params;
    SharedPreferences spref;
    SharedPreferences.Editor sprefEditor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Llayout = (LinearLayout) findViewById(R.id.linearlayout);
        params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    }

    @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;
    }



    public void InitializeObjects() {
        Llayout = (LinearLayout) findViewById(R.id.linearlayout);
        ReminderEditText = (EditText) findViewById(R.id.addReminderText); 
    }


    /*
     * Toast Message
     */
    public void ToastMessage(String Message) {
        Toast.makeText(getApplicationContext(), Message, Toast.LENGTH_SHORT).show();
    }


    public String getReminderText() {
        return ReminderEditText.getText().toString();
    }

    /*
     * onClick method for the set Reminder Button 
     */

    public void setReminder_onClick(View v) {
        /* Don't want a reminder with blank text..*/ 
        if(!TextUtils.isEmpty(getReminderText())) {
            ReminderWidget widget = new ReminderWidget(this);
            widget.setText(getReminderText());
            widget.setTextSize(20);
            widget.setLayoutParams(params);
            widget.displayReminderWidget(Llayout);
        }
    }

}
java(有人能告诉我这段代码有什么问题吗?)


谢谢

如果没有logcat,这有点像是在黑暗中拍摄,但是

public String getReminderText() {
    return ReminderEditText.getText().toString();
}
提醒编辑文本
在此处创建

public void InitializeObjects() {
    Llayout = (LinearLayout) findViewById(R.id.linearlayout);
    ReminderEditText = (EditText) findViewById(R.id.addReminderText); 
}

但是我看不到您在任何地方调用
InitializeObjects
,因此您在null对象上调用
getText()
,因为它还没有被实例化。

请发布您得到的logcat错误。您检查了您的logcat吗?它要说什么?谢谢,这就是问题所在。我的错。我在这里有点粗心。无论如何谢谢你!
public void InitializeObjects() {
    Llayout = (LinearLayout) findViewById(R.id.linearlayout);
    ReminderEditText = (EditText) findViewById(R.id.addReminderText); 
}