-5

プロジェクトでボトムバーを使用していますが、そこにはメールオプションがあり、添付ファイルのオプションがあります。私の問題は、添付ファイルのボタンをクリックすると、件名 n メッセージの編集テキストに書き込まれたデータが消去されることです。添付ファイルを選択した後、その編集テキスト テキストにアクセスするにはどうすればよいですか。この m では、グローバル クラスを使用します。しかし、私はnullオブジェクト参照を取得しています。

public class MainActivity extends AppCompatActivity {


BottomBar nBottomBar;
EditText et1;
EditText et2;
EditText to;
EditText subject;
EditText message;

Uri u;

public static final String DEFAULT = "N/A";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     to= (EditText) findViewById(R.id.to);
     subject = (EditText) findViewById(R.id.subject);
     message= (EditText) findViewById(R.id.message);


    nBottomBar = BottomBar.attach(this, savedInstanceState);
    nBottomBar.setItemsFromMenu(R.menu.menu_main, new OnMenuTabClickListener() {

        @Override
        public void onMenuTabSelected(int i) {
            if (i == R.id.bottombaritemone) {

                PeopleFragment f = new PeopleFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.frame, f).commit();
            } else if (i == R.id.bottombaritemtwo) {

                CardFragment f = new CardFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.frame, f).commit();
            } else if (i == R.id.bottombaritemthree) {

                PhoneFragment f = new PhoneFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.frame, f).commit();
            } else if (i == R.id.bottombaritemfour) {

                MailFragment f = new MailFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.frame, f).commit();
            } else if (i == R.id.bottombaritemfive) {

                FavouriteFragment f = new FavouriteFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.frame, f).commit();
            }

        }

        @Override
        public void onMenuTabReSelected(int i) {

        }


    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.menu_main, menu);

    return true;
}

public void sendSMS(View v) {
    et1 = (EditText) findViewById(R.id.phone);
    et2 = (EditText) findViewById(R.id.msg);
    SmsManager sManager = SmsManager.getDefault();
    StringTokenizer str = new StringTokenizer(et1.getText().toString(), ",");
    while (str.hasMoreElements()) {
        String num = str.nextToken();
        sManager.sendTextMessage(num, null, et2.getText().toString(), null, null);
    }
}

public void call(View v) {
    et1 = (EditText) findViewById(R.id.phone);
    Intent i = new Intent();
    i.setAction(Intent.ACTION_CALL);
    i.setData(Uri.parse("tel:" + et1.getText().toString()));
    startActivity(i);
}

public void attachment(View v) {


    ApplicationConstants.to=to.getText().toString();
    ApplicationConstants.subject=subject.getText().toString();
    ApplicationConstants.message=message.getText().toString();
    Intent i = new Intent();
    i.setAction(Intent.ACTION_GET_CONTENT);
    i.setType("*/*");
    startActivityForResult(i, 123);


}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

        to.setText(ApplicationConstants.to);
        subject.setText(ApplicationConstants.subject);
        message.setText(ApplicationConstants.message);
        Toast.makeText(this, "Data loaded successfully", Toast.LENGTH_LONG).show();


    u = data.getData();

}


public void sendMail(View v) {

    Intent i = new Intent();
    i.setAction(Intent.ACTION_SEND);
    i.putExtra(Intent.EXTRA_EMAIL, new String[]{to.getText().toString()});
    i.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
    i.putExtra(Intent.EXTRA_TEXT, message.getText().toString());
    i.putExtra(Intent.EXTRA_STREAM, u);
    i.setType("message/rfc822");
    startActivity(i.createChooser(i, "select any Email client "));

}

}

LogCat:-

FATAL EXCEPTION: main
                                                                            Process: com.example.hope.bottombar, PID: 24938
                                                                            java.lang.IllegalStateException: Could not execute method for android:onClick
                                                                                at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                                                                                at android.view.View.performClick(View.java:5207)
                                                                                at android.view.View$PerformClick.run(View.java:21168)
                                                                                at android.os.Handler.handleCallback(Handler.java:746)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
                                                                             Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                                                                                at android.view.View.performClick(View.java:5207) 
                                                                                at android.view.View$PerformClick.run(View.java:21168) 
                                                                                at android.os.Handler.handleCallback(Handler.java:746) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5443) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
                                                                             Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
                                                                                at com.example.hope.bottombar.MainActivity.sendMail(MainActivity.java:145)
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
                                                                                at android.view.View.performClick(View.java:5207) 
                                                                                at android.view.View$PerformClick.run(View.java:21168) 
                                                                                at android.os.Handler.handleCallback(Handler.java:746) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5443) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

 

4

1 に答える 1