java - Why doesn't try-Catch work as it's supposed to be? -


i wanted make try-catch block.

in try block there's method checks if radiobutton pressed, if should set enum , go forward , if no radiobutton pressed, nullpointerexception should thrown , app closes (there're coming features aren't finished yet removed them now).

everything saw far didnt fit problem because forgot catch or missspelled method or this.

it works if don't press radiobutton app closes, if press 1 radiobutton app closes again, should go next layout , set enum (depending on radiobutton pressed.

my java-code:

   public void setknowledge() {     setcontentview(r.layout.knowledge_level);      button checking = (button) findviewbyid(r.id.buttonchecking);      checking.setonclicklistener(new view.onclicklistener(){         @override         public void onclick(view v) {             try {                 checkselection();                 setcontentview(r.layout.category_auswahl);             }catch(nullpointerexception n) {                 android.os.process.killprocess(android.os.process.mypid());                 system.exit(0);             }         }     }); }  public knowledge checkselection() {     radiobutton rbnoob = (radiobutton) findviewbyid(r.id.radiobuttonnoob);     radiobutton rbbeginner = (radiobutton) findviewbyid(r.id.radiobuttonbeginner);     radiobutton rbadvanced = (radiobutton) findviewbyid(r.id.radiobuttonadv);     radiobutton rbpro = (radiobutton) findviewbyid(r.id.radiobuttonpro);     radiobutton rbgrandmaster = (radiobutton) findviewbyid(r.id.radiobuttongm);      advertisment();      if(rbnoob.ischecked()) {         return knowledge.noob;     }     else if(rbbeginner.ischecked()) {         return knowledge.beginner;     }     else if(rbadvanced.ischecked()) {         return knowledge.advanced;     }     else if(rbpro.ischecked()) {         return knowledge.pro;     }     else if(rbgrandmaster.ischecked()) {         return knowledge.gm;     }     return null; } 

my xml: (edit: knowledge_level.xml)

<?xml version="1.0" encoding="utf-8"?>    <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#081929" >  <radiogroup     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_margintop="32dp"     app:layout_constrainttop_tobottomof="@+id/testwissenstandtext"     android:layout_marginleft="8dp"     app:layout_constraintleft_toleftof="parent"     android:id="@+id/radiogroup"     app:layout_constraintright_toleftof="@+id/buttonchecking"     android:layout_marginright="8dp"     app:layout_constrainthorizontal_bias="0.538">      <radiobutton         android:id="@+id/radiobuttonnoob"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginleft="0dp"         android:layout_marginright="0dp"         android:layout_margintop="8dp"         android:checked="false"         android:text="keine vorkenntnisse"         android:textalignment="center"         android:textcolor="#e0e0e0"         android:textsize="18sp"         android:textstyle="bold"         app:layout_constrainthorizontal_bias="0.505"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_toleftof="@+id/buttonchecking"         app:layout_constrainttop_tobottomof="@+id/testwissenstandtext"/>      <radiobutton         android:id="@+id/radiobuttonbeginner"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginleft="0dp"         android:layout_marginright="0dp"         android:layout_margintop="8dp"         android:checked="false"         android:text="anfänger"         android:textalignment="center"         android:textcolor="#e0e0e0"         android:textsize="18sp"         android:textstyle="bold"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_toleftof="@+id/radiobuttonnoob"         app:layout_constraintright_torightof="@+id/radiobuttonnoob"         app:layout_constrainttop_tobottomof="@+id/radiobuttonnoob"/>      <radiobutton         android:id="@+id/radiobuttonadv"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginleft="0dp"         android:layout_marginright="0dp"         android:layout_margintop="8dp"         android:text="fortgeschrittener"         android:textalignment="center"         android:textcolor="#e0e0e0"         android:textsize="18sp"         android:textstyle="bold"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_toleftof="@+id/radiobuttonbeginner"         app:layout_constraintright_torightof="@+id/radiobuttonbeginner"         app:layout_constrainttop_tobottomof="@+id/radiobuttonbeginner"/>      <radiobutton         android:id="@+id/radiobuttonpro"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginleft="0dp"         android:layout_marginright="0dp"         android:layout_margintop="8dp"         android:text="pro"         android:textalignment="center"         android:textcolor="#e0e0e0"         android:textsize="18sp"         android:textstyle="bold"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_toleftof="@+id/radiobuttonadv"         app:layout_constraintright_torightof="@+id/radiobuttonadv"         app:layout_constrainttop_tobottomof="@+id/radiobuttonadv"/>      <radiobutton         android:id="@+id/radiobuttongm"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginleft="0dp"         android:layout_marginright="0dp"         android:layout_margintop="8dp"         android:text='"grand master"'         android:textalignment="center"         android:textcolor="#e0e0e0"         android:textsize="18sp"         android:textstyle="bold"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_toleftof="@+id/radiobuttonpro"         app:layout_constraintright_torightof="@+id/radiobuttonpro"         app:layout_constrainttop_tobottomof="@+id/radiobuttonpro"/>  </radiogroup>  <imageview     android:id="@+id/kastenknowledge"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginend="8dp"     android:layout_marginstart="8dp"     android:layout_margintop="16dp"     app:layout_constrainthorizontal_bias="0.517"     app:layout_constraintleft_toleftof="parent"     app:layout_constraintright_torightof="parent"     app:layout_constrainttop_totopof="parent"     app:srccompat="@drawable/kasten"/>  <textview     android:id="@+id/testwissenstandheader"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginbottom="8dp"     android:layout_marginend="8dp"     android:layout_marginstart="8dp"     android:layout_margintop="8dp"     android:text="dein wissensstand?"     android:textalignment="center"     android:textcolor="#511613"     android:textsize="32sp"     android:textstyle="bold"     app:layout_constraintbottom_tobottomof="@+id/kastenknowledge"     app:layout_constraintleft_toleftof="@+id/kastenknowledge"     app:layout_constraintright_torightof="@+id/kastenknowledge"     app:layout_constrainttop_totopof="@+id/kastenknowledge"/>  <textview     android:id="@+id/testwissenstandtext"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginend="16dp"     android:layout_marginstart="16dp"     android:layout_margintop="24dp"     android:text='wie würdest du deinen wissenstand\nbezüglich dem spieleinhalt\nvon "overwatch" beurteilen?'     android:textalignment="center"     android:textcolor="#e0e0e0"     android:textsize="20sp"     app:layout_constrainthorizontal_bias="0.512"     app:layout_constraintleft_toleftof="parent"     app:layout_constraintright_torightof="parent"     app:layout_constrainttop_tobottomof="@+id/testwissenstandheader"/>  <button     android:id="@+id/buttonchecking"     android:layout_width="100dp"     android:layout_height="100dp"     android:layout_marginend="16dp"     android:layout_marginstart="0dp"     android:background="@drawable/button_box"     android:text="c\nl\ni\nc\nk"     android:textallcaps="false"     android:textcolor="#511613"     android:textsize="16sp"     android:textstyle="bold"     app:layout_constraintright_torightof="parent"     android:layout_marginright="16dp"     app:layout_constraintbottom_tobottomof="@+id/radiogroup"     android:layout_marginbottom="8dp"     app:layout_constrainttop_totopof="@+id/radiogroup"     android:layout_margintop="8dp"     app:layout_constraintvertical_bias="0.5"/>    <textview     android:id="@+id/knowledgehint"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginleft="0dp"     android:layout_marginright="0dp"     android:text="wenn du einen wissenstand\nfestgelegt hast, drücke den\nknopf daneben!"     android:textalignment="center"     android:textcolor="#ff4400"     android:textsize="20sp"     android:textstyle="bold|italic"     app:layout_constraintleft_toleftof="parent"     app:layout_constraintright_torightof="parent"     android:layout_margintop="32dp"     app:layout_constrainttop_tobottomof="@+id/radiogroup"/>  </android.support.constraint.constraintlayout> 

error message(s):

08-14 21:01:26.469 4312-4312/? i/process: sending signal. pid: 4312 sig: 9 08-14 21:01:26.470 1521-1590/system_process w/audiotrack: audio_output_flag_fast denied client                                                        --------- beginning of system 08-14 21:01:26.476 1521-1773/system_process i/windowstate: win death: window{ab30a43 u0 com.example.alexander.hashtagnevereverbuggy/com.example.alexander.hashtagnevereverbuggy.mainactivity} 08-14 21:01:26.480 1521-2538/system_process i/activitymanager: process com.example.alexander.hashtagnevereverbuggy (pid 4312) has died 08-14 21:01:26.480 1521-2538/system_process w/activitymanager: force removing activityrecord{ed88b90 u0 com.example.alexander.hashtagnevereverbuggy/.mainactivity t137}: app died, no saved state 08-14 21:01:26.491 1128-1128/? w/surfaceflinger: couldn't log binary event log: overflow. 08-14 21:01:27.104 1776-1958/com.android.launcher d/egl_emulation: eglmakecurrent: 0x7fd4ff628200: ver 2 0 08-14 21:01:27.135 1521-1773/system_process w/inputmethodmanagerservice: got remoteexception sending setactive(false) notification pid 4312 uid 10058 

remove setcontentview(r.layout.category_auswahl); inside onclick listener.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -