あるものactivity
から別のものに行き、スタックからactivity
電流を取り除くと、 . と があるとしましょう。A から B に移動し、B から A に戻り、メソッドまたは を使用してスタックから B アクティビティを削除します。activity
NullPointer exception
class A
class B
finish()
Flag_clear_Top
MainClassとしての「A」クラス
public class MainClass extends Activity{
Button callBTN;
Button messageBTN;
Button emailBTN;
Button referBTN;
TextView nameTXT;
String name ;
String email;
String mobile;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_class_layout);
Intent myIntent = getIntent();
Bundle b = myIntent.getExtras();
name = b.getString("name");
email = b.getString("email");
mobile = b.getString("mobile");
Log.e("Name String", name);
Log.e("email String", email);
Log.e("mobile String", mobile);
nameTXT=(TextView)findViewById(R.id.name_TXT);
callBTN=(Button)findViewById(R.id.call_BTN);
messageBTN=(Button)findViewById(R.id.message_BTN);
emailBTN=(Button)findViewById(R.id.email_BTN);
referBTN=(Button)findViewById(R.id.refer_BTN);
nameTXT.setText(name);
callBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+ mobile));
startActivity(callIntent);
}
});
messageBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.e("MainClass","to find mobile number"+mobile);
Intent intentSendMessage=new Intent(MainClass.this,SmsSender.class);
intentSendMessage.putExtra("mobile_number",mobile);
startActivity(intentSendMessage);
}
});
emailBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intentEmail =new Intent(MainClass.this,EmailSender.class);
intentEmail.putExtra("mail_Str",email);
startActivity(intentEmail);
}
});
referBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intentRefer=new Intent(MainClass.this,References.class);
intentRefer.putExtra("emailAgent",email);
startActivity(intentRefer);
}
});
}
}
参照としての「B」クラス:
package com.cql.ins;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewDebug.FlagToString;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.cqlsys.help.UserFunctions;
public class References extends Activity
{
EditText nameEDt,emailEDt,phoneEDt,commentEDT;
TextView errorTXT;
Button referenceSendBTN;
String emailReferAgent;
// JSON Response node names
private static String KEY_SUCCESS = "status";
private static String KEY_Message ="message";
private static String KEY_ERROR = "error";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.references_layout);
Intent emailIntent = getIntent();
Bundle d = emailIntent.getExtras();
emailReferAgent = d.getString("emailAgent");
nameEDt=(EditText)findViewById(R.id.name_Refer_EDt);
emailEDt=(EditText)findViewById(R.id.email_Refer_EDT);
phoneEDt=(EditText)findViewById(R.id.phone_refer_EDT);
commentEDT=(EditText)findViewById(R.id.comment_Refer_EDT);
errorTXT=(TextView)findViewById(R.id.errorTXT);
referenceSendBTN=(Button)findViewById(R.id.refer_send_BTN);
referenceSendBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String nameReferStr = nameEDt.getText().toString();
String emailReferStr = emailEDt.getText().toString();
String phoneReferStr =phoneEDt.getText().toString();
String commentReferStr =commentEDT.getText().toString();
UserFunctions userFunction = new UserFunctions();
JSONObject json =userFunction.referUser(nameReferStr, emailReferStr, phoneReferStr,commentReferStr,emailReferAgent);
// check for response
try {
if (json.getString(KEY_SUCCESS) != null) {
errorTXT.setText("hello");
String res = json.getString(KEY_SUCCESS);
Log.e("REferences Status Tag", res);
if(Boolean.parseBoolean(res) == true){
// user successfully submit
//Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_SHORT).show();
Intent intentbackMainClass=new Intent(References.this,MainClass.class);
//intentbackMainClass.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intentbackMainClass);
finish();
}else{
// Error in submit the data
errorTXT.setText("Error occured in registration");
}
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
しかし、次の例外が発生します。
** threadid=1: キャッチされない例外 (group=0x4001d800) で終了するスレッド): java.lang.RuntimeException: アクティビティ ComponentInfo を開始できません {com.cqlsys.insagent/com.cql.ins.MainClass}: java.lang.NullPointerException **
01-19 02:43:27.507: E/AndroidRuntime(13801): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-19 02:43:27.507: E/AndroidRuntime(13801): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-19 02:43:27.507: E/AndroidRuntime(13801): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-19 02:43:27.507: E/AndroidRuntime(13801): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-19 02:43:27.507: E/AndroidRuntime(13801): at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 02:43:27.507: E/AndroidRuntime(13801): at android.os.Looper.loop(Looper.java:123)
01-19 02:43:27.507: E/AndroidRuntime(13801): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-19 02:43:27.507: E/AndroidRuntime(13801): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 02:43:27.507: E/AndroidRuntime(13801): at java.lang.reflect.Method.invoke(Method.java:521)
01-19 02:43:27.507: E/AndroidRuntime(13801): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-19 02:43:27.507: E/AndroidRuntime(13801): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-19 02:43:27.507: E/AndroidRuntime(13801): at dalvik.system.NativeStart.main(Native Method)
01-19 02:43:27.507: E/AndroidRuntime(13801): Caused by: java.lang.NullPointerException
01-19 02:43:27.507: E/AndroidRuntime(13801): at com.cqlsys.insagent.MainClass.onCreate(MainClass.java:39)
01-19 02:43:27.507: E/AndroidRuntime(13801): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-19 02:43:27.507: E/AndroidRuntime(13801): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-19 02:43:27.507: E/AndroidRuntime(13801): ... 11 more
どうすればこの問題を解決できますか?