here are my classes, when i run the application it crashes on selection and gives me a null error. I'm designing a revision app and am trying to do it without having to make a class for every topic covered any help would be much appreciated.
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.w3c.dom.Text;
public class TheoryMain extends Activity {
TheoryTopicList ttl;
TextView tv1;
String choice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.theory_layout);
ttl = new TheoryTopicList();
ttl.getChoice();
tv1 = (TextView) findViewById(R.id.theory_tv);
switch(choice){
case("Photo-Electric effect"):
tv1.setText(getString(R.string.photo_electric));
break;
case("Photons and Electrons"):
tv1.setText(getString(R.string.photons_electrons));
break;
case("de Broglie wavelength"):
tv1.setText(getString(R.string.de_broglie));
break;
case("Types of particles"):
tv1.setText(getString(R.string.particles));
break;
case("Interactions"):
tv1.setText(getString(R.string.interactions));
break;
case("Radiation"):
tv1.setText(getString(R.string.radiation));
break;
case("Voltage, Current and Resistance(Ohms law)"):
tv1.setText(getString(R.string.ohms_law));
break;
case("Circuits"):
tv1.setText(getString(R.string.circuits));
break;
case("Power and Efficiency"):
tv1.setText(getString(R.string.power_efficiency));
break;
case("Alternating Current and oscilloscope graphs"):
tv1.setText(getString(R.string.ac_graphs));
break;
case("E.M.F and internal Resistance"):
tv1.setText(getString(R.string.emf_resistance));
break;
}
}
}
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class TheoryTopicList extends ListActivity {
String[] display = {"Photo-Electric effect", "Photons and Electrons", "de Broglie wavelength", "Types of particles",
"Interactions", "Radiation", "Voltage, Current and Resistance(Ohms law)", "Circuits",
"Power and Efficiency","Alternating Current and oscilloscope graphs", "E.M.F and internal Resistance"};
String choice;
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
choice = display[position];
Intent intent = new Intent("com.revisonapp.alec.alevelphysics.THEORYMAIN");
startActivity(intent);
}
public String getChoice(){
return choice;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(TheoryTopicList.this,android.R.layout.simple_list_item_1,display));
}
}