任何人都可以帮我解决这个问题吗?
11-15 14:37:17.325 18731-18731/com.myaplication.marbelmoneymanager E/ViewRootImpl: sendUserActionEvent() mView == null
FATAL EXCEPTION: main
Process: com.myaplication.marbelmoneymanager, PID: 18731
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myaplication.marbelmoneymanager/com.myaplication.marbelmoneymanager.Income.NewIncomeActivity}: java.lang.StringIndexOutOfBoundsException: length=0; regionStart=3; regionLength=2
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2436)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2498)
at android.app.ActivityThread.access$900(ActivityThread.java:179)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5641)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1288)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1104)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.StringIndexOutOfBoundsException: length=0; regionStart=3; regionLength=2
at java.lang.String.startEndAndLength(String.java:588)
at java.lang.String.substring(String.java:1475)
at com.myaplication.marbelmoneymanager.Income.NewIncomeActivity.onCreate(NewIncomeActivity.java:102)
at android.app.Activity.performCreate(Activity.java:5484)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2498)
at android.app.ActivityThread.access$900(ActivityThread.java:179)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5641)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1288)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1104)
at dalvik.system.NativeStart.main(Native Method)
我认为问题在于此代码
this.xday = this.tgl.substring(3, 5);
因为日志猫把我带到了这里
public void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_newincome);
this.spin = ((Spinner)findViewById(R.id.spinCategory));
this.txtAmount = ((TextView)findViewById(R.id.txtAmount));
this.txtDetail = ((TextView)findViewById(R.id.txtDetail));
this.btnEdit = ((Button)findViewById(R.id.btnCat));
Bundle localBundle = getIntent().getExtras();
this.ciDS = new CategoryInDataSource(this);
this.ciDS.open();
this.iDS = new IncomeDataSource(this);
this.iDS.open();
loadSpinnerData();
if (localBundle != null)
{
this.txtAmount.setText(localBundle.getString("jumlah"));
this.txtDetail.setText(localBundle.getString("ket"));
this.tgl = localBundle.getString("temp");
this.cat = localBundle.getString("cat");
this.minDate = localBundle.getString("min");
}
this.xday = this.tgl.substring(3, 5);
this.xmonth = this.tgl.substring(0, 2);
this.xyear = this.tgl.substring(7, 11);
this.waktu = (this.xyear + "-" + this.xmonth + "-" + this.xday + " 00:00:00");
this.btnEdit.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramView)
{
NewIncomeActivity.this.intent = new Intent(NewIncomeActivity.this, IncomeCategoryActivity.class);
NewIncomeActivity.this.intent.putExtra("jumlah", NewIncomeActivity.this.txtAmount.getText().toString());
NewIncomeActivity.this.intent.putExtra("ket", NewIncomeActivity.this.txtDetail.getText().toString());
NewIncomeActivity.this.intent.putExtra("temp", NewIncomeActivity.this.tgl);
NewIncomeActivity.this.intent.putExtra("min", NewIncomeActivity.this.minDate);
NewIncomeActivity.this.intent.putExtra("cat", NewIncomeActivity.this.cat);
NewIncomeActivity.this.startActivity(NewIncomeActivity.this.intent);
NewIncomeActivity.this.finish();
}
});
}
答案 0 :(得分:1)
我最好的猜测是localBundle.getString(" temp");没有返回任何原因,因为错误表示相关字符串的长度为0.我跟踪它以确保它返回你想要的字符串。