My app was working for a while but all of a sudden it started to crash every time I click on a TextView
. when running in debug mode it goes through a lot of lib classes until it eventually just stops and crashes before it can even reach my onclick method where I wrote what should happen when I click that TextView
. since I started to work with android studio two days ago, I'm not that good at debugging yet and can just say that my own code seems to work fine, so at this point, I'm kinda desperate and have no idea what to do. I hope anyone can help me. I'll see if I can upload the code (first time I'm posting here as well ^^")
//tools Random rn; TextView selected; int index1, index2; long max, min; //attribute double numberofdigits; long number; int orange; //layout LinearLayout container; ArrayList<Integer> digits; ArrayList<TextView> digitboxes; Button doublebtn, halfebtn; //popup AlertDialog.Builder dialogbuilder; AlertDialog dialog; NumberPicker numberpicker; Button startbtn; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_down_to_one); //tools rn = new Random(); selected = null; index1 = 0; index2 = 0; //attribute orange = 0x7DFFB200; generatenumber(); //layout container = (LinearLayout)findViewById(R.id.container); digits = new ArrayList<Integer>(); digitboxes = new ArrayList<TextView>(); doublebtn = (Button)findViewById(R.id.doublebtn); halfebtn = (Button)findViewById(R.id.halfebtn); doublebtn.setOnClickListener(this); halfebtn.setOnClickListener(this); refreshnumber(); } public void onClick(View v) {... it never reaches this part (when setting a breakpoint here the app crashes before being able to stop at this line) every method called in the code above works fine (at least my app doesnt crash and the code does what its supposed to do) ill add the part where the textviews are created: private void refreshnumber(){ if(!digitboxes.isEmpty()){ //btw do i need this if-statement? i wasnt sure and i thought safety first digitboxes.clear(); } long temp = number; int counter = 0; //layoutparams for all digitboxes LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT); do{ //calculation long oom = (long) Math.pow(10, (double) counter); //order of magnitude of the current digit int digit = (int) ((long) (temp%(oom*10))/oom); //removes every 0 behind the wanted digit digits.add(counter, ziffer); //add digit to list temp -= (long) digit*oom; //make current digit in temp to 0 //layout TextView digitbox = new TextView(this); //temporary reference to a new digitbox digitbox.setId(counter); digitbox.setText(String.valueOf(ziffer)); //add digit to textview digitbox.setLayoutParams(lp); digitbox.setTextSize(50); digitbox.setClickable(true); digitboxes.add(counter, ziffernbox); //add new digit box to list of digitboxes counter++; //add onclicklistener to digitbox digitbox.setOnClickListener(this); }while(temp>0); reverseorder(); //add all digitboxes to container for(TextView tv : ziffernboxen){ container.addView(tv); } }
Please ignore any typo in the code that might occure, my original code is partly in German and I tried to translate everything to english and maybe I made a mistake during the translation of all the variable and method names. but as I said, the program runs through every line I wrote without errors or crashing. (I know there is still a possibility that my code is flawed but a few hours ago it worked perfectly)
i think i wrote enough ^^" i hope anybody is actually going to read that and can help me
https://stackoverflow.com/questions/66576231/onclicklistener-crashes-my-android-app-i-think March 11, 2021 at 11:54AM
没有评论:
发表评论