.setText() crashes my android app

zpout2008

New Member
I have tried many other questions on this site today but none of them have been helpful, i seem to have identical syntax that works for other people but every time i hit send (when i want my text fields to update) my app just crashes, I have tried a bunch of different syntax for the setText() method but nothing has worked.Thanks for any help in advancethis is my main class\[code\]package com.example.myapp;import android.app.Activity;import java.io.IOException;import java.util.ArrayList;import android.app.Activity;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;import org.apache.http.client.*;import org.apache.http.client.methods.*;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.util.EntityUtils;public class TestprojectsActivity extends Activity { private int index; private int QsClicked = 0; private ArrayList<String> categories = new ArrayList<String>(); private ArrayList<Button> buttons = new ArrayList<Button>(); Button b1; Button b2; Button b3; Button b4; Button changer; private int Qselected; TextView txt; EditText edit; private ArrayList<String> questions = new ArrayList<String>(); private int qnum = 0; // updates all the buttons so we can see more categories public void updateButtons(View v){ for(int i = 0; i < 4; i++){ if(index >= categories.size()){ index = 0; } buttons.get(i).setText(categories.get(index)); index++; } } public void Q1(View v){ setContentView(R.layout.sub); Qselected = index; //send(null); } public void Q2(View v){ setContentView(R.layout.sub); Qselected = (index+1); //send(null); } public void Q3(View v){ setContentView(R.layout.sub); Qselected = (index+2); //send(null); } public void Q4(View v){ setContentView(R.layout.sub); Qselected = (index+3); //send(null); } public void send(View v){ edit.setText("WHY ISNT THIS WORKING?"); if(qnum < questions.size()){ txt.setText("i work!"); qnum++; } else{ qnum = 0; System.exit(0); } }/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); index = 0; b1 = (Button) findViewById(R.id.B1); buttons.add(b1); b2 = (Button) findViewById(R.id.B2); buttons.add(b2); b3 = (Button) findViewById(R.id.B3); buttons.add(b3); b4 = (Button) findViewById(R.id.B4); buttons.add(b4); txt = (TextView) findViewById(R.id.textView1); edit = (EditText) findViewById(R.id.editText2); categories.add("dumb questions"); categories.add("smart questions"); questions.add("hi there, what is your name?"); questions.add("what did you have for breakfast today?"); questions.add("how old are you?"); questions.add("what color is your hair?"); updateButtons(null);}}\[/code\]this is my main xml\[code\]<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/layoutrowtop"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><Button android:id="@+id/B4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="B4" android:onClick="Q4" /><Button android:id="@+id/B3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="B3" android:onClick="Q3" /><Button android:id="@+id/B2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="B2" android:onClick="Q2" /><Button android:id="@+id/B1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="B1" android:onClick="Q1" /><Button android:id="@+id/Button05" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="More Categories" android:onClick="updateButtons" /></LinearLayout>\[/code\]this is my sub xml (i use it so i can have another layout)\[code\] <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.22" android:text="Question" /> <EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.51" android:ems="10" android:inputType="text" /> <Button android:id="@+id/send" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.08" android:text="Send" android:onClick="send" /> </LinearLayout>\[/code\]
 
Back
Top