[英]App crashing when running on devices, when going to main activity
So the app works on emulator perfectly, however when i tried to run it on devices, it crash on main activity.所以该应用程序可以在模拟器上完美运行,但是当我尝试在设备上运行它时,它会在主要活动上崩溃。 please i need help, will really appreciate it.
请我需要帮助,将非常感激。
heres the main activity java这是主要活动 java
package com.example.dashboard;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.DisplayCutout;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
TextView day,month,year;
public CardView draftCard, cardsCard, todoCard, moneyCard, linkedinCard;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
//definingdates
day = findViewById(R.id.day);
month = findViewById(R.id.month);
year = findViewById(R.id.year);
Date currentTime = Calendar.getInstance().getTime();
String formattedDate = DateFormat.getDateInstance(DateFormat.FULL).format(currentTime);
String[] splitDate = formattedDate.split(",");
Log.d("myLog", currentTime.toString());
Log.d("myLog", formattedDate);
//setdate
month.setText(splitDate[1]);
day.setText(splitDate[0]);
year.setText(splitDate[2]);
Log.d("myLog", splitDate[0].trim());
Log.d("myLog", splitDate[1].trim());
Log.d("myLog", splitDate[2].trim());
//definingcards
draftCard = findViewById(R.id.draftCard);
cardsCard = findViewById(R.id.cardsCard);
moneyCard = findViewById(R.id.moneyCard);
todoCard = findViewById(R.id.todoCard);
linkedinCard = findViewById(R.id.linkedinCard);
//addingclicklistener
draftCard.setOnClickListener(this);
cardsCard.setOnClickListener(this);
moneyCard.setOnClickListener(this);
todoCard.setOnClickListener(this);
linkedinCard.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent i ;
switch (v.getId()) {
case R.id.draftCard: i = new Intent(this, draftcard.class);
startActivity(i);
break;
case R.id.cardsCard: i = new Intent(this, cardscard.class);
startActivity(i);
break;
case R.id.moneyCard: i = new Intent(this, moneycard.class);
startActivity(i);
break;
case R.id.todoCard: i = new Intent(this, todocard.class);
startActivity(i);
break;
case R.id.linkedinCard: i = new Intent(this, linkedincard.class);
startActivity(i);
break;
default:break;
}
}
}
and the stack traces和堆栈跟踪
2021-01-28 01:29:52.465 28496-28496/? I/ample.dashboar: Late-enabling -Xcheck:jni
2021-01-28 01:29:52.517 28496-28496/? E/ample.dashboar: Unknown bits set in runtime_flags: 0x8000
2021-01-28 01:29:52.528 28496-28496/? I/ample.dashboar: Reinit property: dalvik.vm.checkjni= false
2021-01-28 01:29:52.567 28496-28496/? E/libc: Access denied finding property "runtime.mmitest.isrunning"
2021-01-28 01:29:52.579 28496-28496/? D/ActivityThread: Attach thread to application
2021-01-28 01:29:52.761 28496-28496/com.example.dashboard I/ample.dashboar: QarthPatchMonintor::Init
2021-01-28 01:29:52.761 28496-28496/com.example.dashboard I/ample.dashboar: QarthPatchMonintor::StartWatch
2021-01-28 01:29:52.762 28496-28496/com.example.dashboard I/ample.dashboar: QarthPatchMonintor::WatchPackage: /data/hotpatch/fwkhotpatch/
2021-01-28 01:29:52.762 28496-28496/com.example.dashboard I/ample.dashboar: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/com.example.dashboard
2021-01-28 01:29:52.762 28496-28496/com.example.dashboard I/ample.dashboar: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/all
2021-01-28 01:29:52.762 28496-28496/com.example.dashboard I/ample.dashboar: QarthPatchMonintor::Run
2021-01-28 01:29:52.764 28496-28564/com.example.dashboard I/ample.dashboar: QarthPatchMonintor::Reading
2021-01-28 01:29:52.764 28496-28564/com.example.dashboard I/ample.dashboar: QarthPatchMonintor::CheckNotifyEvent
2021-01-28 01:29:52.764 28496-28564/com.example.dashboard I/ample.dashboar: QarthPatchMonintor::CheckNotifyEvent before read
2021-01-28 01:29:52.780 28496-28539/com.example.dashboard I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.dashboard#10312#256
2021-01-28 01:29:52.780 28496-28539/com.example.dashboard I/HwApiCacheMangerEx: apicache path=/storage/1538-291C state=mounted key=com.example.dashboard#10312#256
2021-01-28 01:29:52.786 28496-28539/com.example.dashboard I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.dashboard#10312#0
2021-01-28 01:29:52.786 28496-28539/com.example.dashboard I/HwApiCacheMangerEx: apicache path=/storage/1538-291C state=mounted key=com.example.dashboard#10312#0
2021-01-28 01:29:52.800 28496-28539/com.example.dashboard I/AwareBitmapCacher: init processName:com.example.dashboard pid=28496 uid=10312
2021-01-28 01:29:52.857 28496-28577/com.example.dashboard E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@a6ca3cf
2021-01-28 01:29:52.959 28496-28496/com.example.dashboard V/ActivityThread: callActivityOnCreate
2021-01-28 01:29:52.989 28496-28496/com.example.dashboard V/HwWidgetFactory: : successes to get AllImpl object and return....
2021-01-28 01:29:53.029 28496-28496/com.example.dashboard W/ample.dashboar: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-01-28 01:29:53.031 28496-28496/com.example.dashboard W/ample.dashboar: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-01-28 01:29:53.120 28496-28496/com.example.dashboard D/ActivityThread: add activity client record, r= ActivityRecord{6e77753 token=android.os.BinderProxy@3a3b4ad {com.example.dashboard/com.example.dashboard.Splash}} token= android.os.BinderProxy@3a3b4ad
2021-01-28 01:29:53.171 28496-28618/com.example.dashboard D/HiTouch_PressGestureDetector: onAttached, package=com.example.dashboard, windowType=1, mHiTouchRestricted=false
2021-01-28 01:29:53.188 28496-28570/com.example.dashboard I/iGraphics: [0020080c] pn: com.example.dashboard, p: 28496
2021-01-28 01:29:53.188 28496-28570/com.example.dashboard I/iGraphics: [0030080c] no spt app: com.example.dashboard
2021-01-28 01:29:53.216 28496-28570/com.example.dashboard D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2021-01-28 01:29:53.225 28496-28570/com.example.dashboard W/Gralloc3: mapper 3.x is not supported
2021-01-28 01:29:53.318 28496-28496/com.example.dashboard I/HwViewRootImpl: removeInvalidNode jank list is null
2021-01-28 01:29:57.800 28496-28496/com.example.dashboard D/AwareBitmapCacher: handleInit switch not opened pid=28496
2021-01-28 01:29:57.918 28496-28496/com.example.dashboard D/HwFrameworkSecurityPartsFactory: HwFrameworkSecurityPartsFactory in.
2021-01-28 01:29:57.919 28496-28496/com.example.dashboard I/HwFrameworkSecurityPartsFactory: add HwFrameworkSecurityPartsFactory to memory.
2021-01-28 01:29:57.972 28496-28496/com.example.dashboard W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@94573fa
2021-01-28 01:29:57.987 28496-28496/com.example.dashboard V/ActivityThread: callActivityOnCreate
2021-01-28 01:29:58.012 28496-28496/com.example.dashboard I/OverScrollerOptimization: start init SmartSlideOverScroller and get the overscroller config
2021-01-28 01:29:58.012 28496-28496/com.example.dashboard I/OverScrollerOptimization: get the overscroller config
2021-01-28 01:29:58.111 28496-28496/com.example.dashboard D/myLog: Thu Jan 28 01:29:58 GMT+08:00 2021
2021-01-28 01:29:58.111 28496-28496/com.example.dashboard D/myLog: Thursday, 28 January 2021
2021-01-28 01:29:58.112 28496-28496/com.example.dashboard I/BlockMonitor: dispatchingThrewException In MainThread
2021-01-28 01:29:58.112 28496-28496/com.example.dashboard D/AndroidRuntime: Shutting down VM
2021-01-28 01:29:58.112 28496-28496/com.example.dashboard I/QarthLog: [PatchStore] createDisableExceptionQarthFile
2021-01-28 01:29:58.112 28496-28496/com.example.dashboard I/QarthLog: [PatchStore] create disable file for com.example.dashboard uid is 10312
2021-01-28 01:29:58.114 28496-28496/com.example.dashboard E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dashboard, PID: 28496
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dashboard/com.example.dashboard.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3961)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
at com.example.dashboard.MainActivity.onCreate(MainActivity.java:47)
at android.app.Activity.performCreate(Activity.java:8086)
at android.app.Activity.performCreate(Activity.java:8074)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3755)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3961)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
2021-01-28 01:29:58.133 28496-28496/com.example.dashboard I/Process: Sending signal. PID: 28496 SIG: 9
i tried already removing the year.setText(splitDate[2]);我已经尝试删除 year.setText(splitDate[2]); and log for 2, everything works well.
并记录 2,一切正常。 but i really need to know what really the problems as the other month and day works pretty well.
但我真的需要知道真正的问题是什么,因为其他月份和一天工作得很好。
thank you guys感谢你们
Format date in the format you definitely control.以您绝对控制的格式格式化日期。 For example:
例如:
Date currentTime = Calendar.getInstance().getTime();
String formatted = (new SimpleDateFormat("dd MMMM yyyy")).format(currentDate);
String[] splitDate = formatted.split(" ");
month.setText(splitDate[1]);
day.setText(splitDate[0]);
year.setText(splitDate[2]);
Print out formattedDate
and make sure that delimiter (comma) is the correct choice in your case.打印出
formattedDate
并确保分隔符(逗号)在您的情况下是正确的选择。 It seems that due to different locales, the dates format are different.似乎由于不同的语言环境,日期格式不同。
I think the issue is with your switch statement for onClick based on the error.我认为问题在于您基于错误的 onClick 的 switch 语句。 Start with taking that out by comment and see if you get still get the crash.
从通过评论删除它开始,看看你是否仍然遇到崩溃。 If not then investigate the switch (v.getId()).
如果没有,则调查开关 (v.getId())。 I suspect that is returning less than the array you are expecting.
我怀疑返回的数组少于您期望的数组。 Hope it helps a little!
希望它有一点帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.