微信公众号开发全流程指南与避坑实践
2026/8/13 9:35:12
valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{vala=10/0}classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivityclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivityclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivityclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivityvalbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,MiddleActivity::class.java)intent.putExtra("data",100)startActivity(intent)}valtvMessage=findViewById<TextView>(R.id.tv_message)valbtnGo=findViewById<Button>(R.id.btn_go)valdata=intent.getIntExtra("data",0)if(data==0){throwIllegalArgumentException("data is 0")}tvMessage.text="data:$data"btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{vala=10/0}classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}valtvResult=findViewById<TextView>(R.id.tv_result)valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{Thread{tvResult.text="1 + 2 = 3"}.start()}classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}奔溃,退回桌面 系统打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}系统打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. throwable.printStackTrace() 打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}奔溃,白屏 系统打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. throwable.printStackTrace() 打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. APP 自动重启,打开到 LoginActivityclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}奔溃,白屏 系统打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. throwable.printStackTrace() 打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. APP 自动重启,打开到 LoginActivityvalbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{valname:String?=nullvallength=name!!.lengthprintln(length)}classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}奔溃,白屏 系统打印:java.lang.NullPointerException APP 自动重启,打开到 LoginActivityclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}奔溃,白屏 系统打印:java.lang.NullPointerException throwable.printStackTrace() 打印:java.lang.NullPointerException APP 自动重启,打开到 LoginActivityclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}奔溃,白屏 系统打印:java.lang.NullPointerException throwable.printStackTrace() 打印:java.lang.NullPointerException APP 自动重启,打开到 LoginActivityclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}奔溃,白屏 系统打印:java.lang.NullPointerException throwable.printStackTrace() 打印:java.lang.NullPointerException APP 自动重启,打开到 LoginActivityvalbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{Thread{vala=10/0}.start()}classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivityclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zeroclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivityclassMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivityvalbtnTest=findViewById<Button>(R.id.btn_test)btnTest.setOnClickListener{System.exit(0)}System.exit(0)退回桌面System.exit(1)退回桌面valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{System.exit(0)}System.exit(0)退回桌面,白屏 APP 自动重启,打开到 LoginActivitySystem.exit(1)退回桌面,白屏 APP 自动重启,打开到 LoginActivityvalbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,MiddleActivity::class.java)intent.putExtra("data",100)startActivity(intent)}valtvMessage=findViewById<TextView>(R.id.tv_message)valbtnGo=findViewById<Button>(R.id.btn_go)valdata=intent.getIntExtra("data",0)if(data==0){throwIllegalArgumentException("data is 0")}tvMessage.text="data:$data"btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{System.exit(0)}System.exit(0)退回桌面,白屏 APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100System.exit(1)退回桌面,白屏 APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100