Not able to start activity which is in another package (from intent) - android

I've got an activity where I can add bookmarks to a favourites list. Each favourite has got a button. When I click that button I have to go to that specific activity. But it shows me an error. The app doesn't crash, but the bookmarked activity isn't started from the click.
Here is the code for the "Favourites" activity:
public class FavouritesActivity extends Activity {
private TextView mEmptyText;
private LinearLayout mBookmarkLayout;
private Context mContext;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favourites_layout);
mContext = this;
mEmptyText = (TextView) findViewById(R.id.empty_textview);
mBookmarkLayout = (LinearLayout) findViewById(R.id.bookmark_insert_point);
getAllKeys();
}
private void getAllKeys()
{
SharedPreferences sp = this.getSharedPreferences("favs", MODE_PRIVATE);
Map<String,?> keys = sp.getAll();
int count = 0;
for(Map.Entry<String,?> entry : keys.entrySet())
{
String value = entry.getValue().toString();
System.out.println("!!!!!!!!!!!!!!!!!value = "+value);
String delimiter = ",";
String[] values_array = value.split(delimiter);
addBookmark(values_array);
count++; //keep track of the number of bookmarks
}
//if there are no bookmarks, display a text view saying so. Otherwise, make the text view go away
if (count == 0)
{
mEmptyText.setVisibility(View.VISIBLE);
mEmptyText.setText(getString(R.string.no_favs));
}
else
mEmptyText.setVisibility(View.GONE);
}
private void addBookmark(String[] values_array)
{
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.fav_individual, null);
TextView text = (TextView) v.findViewById(R.id.bookmark_text);
text.setSelected(true);
ImageButton button = (ImageButton) v.findViewById(R.id.bookmark_button);
v.getContext();
text.setText(values_array[1]);
final String myClass = values_array[0];
button.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Class<?> cl = null;
try {
cl = Class.forName(myClass);
Intent myIntent = new Intent(mContext, cl);
startActivity(myIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
});
// insert into main view
mBookmarkLayout.addView(v, 0, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
System.out.println("!!!!!!!!!!!!!!!!!!!!Just added a view");
}
}
The error is the onClick method, exactly in this line:
cl = Class.forName(myClass);
It gives me a ClassNotFoundException.
It seems that with this code I'm able to start an activity which is inside this package. But the problem is that the activity I want to start is inside a different package. The logcat says that it coulnd't find the activity in the current package.
So how can I open an activity from a different package in my case? Tha activity is declared in the manifest file.
Thank you.

Did you import the other package in your FavouritesActivity ?
Add this line at the top of your code and replace the words to match with your other package:
import com.yourotherpackage.name.yourclassname;

Related

How to access a TextView located in a Table Layout

I made a TableLayout 3x3 in "Activity A"(Chose a Table Layout, because I thought it suits my needs)
7 of the 9 cells are clickable and open "Activity B" which is a custom number picker I made.
I used an intent to pass an array and other data to activiy B
The idea of my number picker is to set a value in the cell I just clicked in Activiy A(I wanted something like the calendarDatePicker)
In "Activity B" I have a method to update the values from "Activity A" and finish() "Activity B" when an image View is clicked wich works very fine except that it does not set the value for the clicked Text View
How can I set the TextValue from another activity when the TextValue is contained in a Table Layout?
I don't use intent, because honestly I don't know how to handle it when the "Activity B" is closed.
I mean where in "Activity A" should I handle this intent from "Activity B"
Using the debugger I found out that trying to set the text using the TextView Id does not works as it shows a "null" object in the debugger.
Activiy A
package com.example.racu.threebythree;
public class threebythree extends AppCompatActivity {
public static ArrayList<Integer> ColumnA = new ArrayList<Integer>();
public static ArrayList<Integer> ColumnB = new ArrayList<Integer>();
public static ArrayList<Integer> ColumnC = new ArrayList<Integer>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_three_by_three);
for (int i = 1; i < 28; i++) {
if (i > 0 && i < 10)
ColumnA.add(i);
if (i > 10 && i < 19)
ColumnB.add(i);
if (i > 19 && i < 28)
ColumnC.add(i);
}
}
public void openNumberPicker(View v) {
// I used this to "guess" the location of the cell in the table layout as I could not find a way to do it.
String cellName = v.getResources().getResourceName(v.getId());
String cellLetter = cellName.substring(cellName.lastIndexOf("/") + 1);
// Send intent
Intent intent = new Intent(this, NumberPicker.class);
intent.putExtra("Id", (cellLetter.substring(0, 1) + cellLetter.substring(2)).toUpperCase());
switch (cellLetter.substring(0, 1)) {
case ("a"):
intent.putIntegerArrayListExtra("Column", ColumnA);
break;
case ("b"):
intent.putIntegerArrayListExtra("Column", ColumnB);
break;
case ("c"):
intent.putIntegerArrayListExtra("Column", ColumnC);
break;
}
intent.putExtra("Cell ID", v.getId());
startActivity(intent);
}
}
Avtivity B
package com.example.racu.threebythree;
public class NumberPicker extends AppCompatActivity {
GridView numberPicker;
ArrayList<Integer> numbersToDisplay;
TextView viewToDisplay;
ImageView ok, cancel;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_number_picker);
numberPicker = (GridView) findViewById(R.id.arrayNumbers);
viewToDisplay = (TextView) findViewById(R.id.number_to_select);
ok = (ImageView) findViewById(R.id.add_number_to_card);
ok.setClickable(false);
Intent intent = getIntent();
String idFromIntent = intent.getStringExtra("Id");
numbersToDisplay = intent.getIntegerArrayListExtra("Letter");
TextView numberPosition = (TextView) findViewById(R.id.numberPosition);
numberPosition.setText(idFromIntent);
final TextView chosenNumber = (TextView) findViewById(R.id.chosenNumber);
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this, R.layout.number_for_picker, numbersToDisplay);
numberPicker.setAdapter(adapter);
numberPicker.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
chosenNumber.setText(((TextView) v).getText());
ok.setImageResource(R.drawable.ok_blue);
ok.setClickable(true);
}
});
}
public void updateThreByThree(View v) {
Intent intent = getIntent();
int currentCell = intent.getIntExtra("Cell ID", 0);
String idFromIntent = intent.getStringExtra("Id").substring(0, 1);
TextView chosenNumber = (TextView) findViewById(R.id.chosenNumber);
// Here I try to Set the text to the cell in Activity A, using its R.id, but in the debugger I get a null reference, therefore my app crashes
TextView currentCellToEdit = (TextView) findViewById(currentCell);
currentCellToEdit.setText(chosenNumber.getText());
int temp = Integer.parseInt(chosenNumber.getText().toString());
switch (idFromIntent) {
case "A":
threebythree.ColumnA.remove(Integer.valueOf(temp));
break;
case "B":
threebythree.ColumnB.remove(Integer.valueOf(temp));
break;
case "C":
threebythree.ColumnC.remove(Integer.valueOf(temp));
break;
}
finish();
}
public void cancel(View view) {
finish();
}
}
Thanks to Pavan for the hint I found two more very helpful post here and this one was EXACTLY what I was looking for.
Like that ( make sure you give the TableLayout an id ):
TableLayout tl = (TableLayout)findViewById( R.id.tableLayout );
TextView tv = (TextView)tl.findViewById( R.id.textView );

unable to deploy data in an intent

problem: I set point breaks at the following code:
intent.putExtra(WorkoutRoutinesActivity.EXTRA_WORKOUT_NAME, workoutName);
intent.putExtra(WorkoutRoutinesActivity.EXTRA_WORKOUT_DAYS, workoutDays);
, both showed up as null when I ran the app in debug mode. workoutName contains a simple String that is passed to a new activity, whereas workoutDays constains an array of String.
the full code is provided below:
public class CreateWorkoutActivity extends Activity {
public final String TAG = this.getClass().getSimpleName();
protected String[] workoutDays = new String[7];
protected String workoutName;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_workout);
Button mNextButton = (Button) findViewById(R.id.next_button1);
CheckBox satBox = (CheckBox) findViewById(R.id.sat_checkbox);
CheckBox sunBox = (CheckBox) findViewById(R.id.sun_checkbox);
CheckBox monBox = (CheckBox) findViewById(R.id.mon_checkbox);
CheckBox tuesBox = (CheckBox) findViewById(R.id.tues_checkbox);
CheckBox wedBox = (CheckBox) findViewById(R.id.wed_checkbox);
CheckBox thursBox = (CheckBox) findViewById(R.id.thurs_checkbox);
CheckBox friBox = (CheckBox) findViewById(R.id.fri_checkbox);
final EditText mWorkoutName = (EditText) findViewById(R.id.workout_name1);
workoutName = mWorkoutName.getText().toString();
Log.i(TAG, workoutName);
if (satBox.isChecked()) {
workoutDays[0] = new String(satBox.getText().toString());
}
if (sunBox.isChecked()) {
workoutDays[1] = new String(sunBox.getText().toString());
}
if (monBox.isChecked()) {
workoutDays[2] = new String(monBox.getText().toString());
}
if (tuesBox.isChecked()) {
workoutDays[3] = new String(tuesBox.getText().toString());
}
if (wedBox.isChecked()) {
workoutDays[4] = wedBox.getText().toString();
}
if (thursBox.isChecked()) {
workoutDays[5] = satBox.getText().toString();
}
if (friBox.isChecked()) {
workoutDays[6] = friBox.getText().toString();
Log.i(TAG, workoutDays[6]);
}
mNextButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i(TAG, workoutDays.toString());
Intent intent = new Intent(CreateWorkoutActivity.this, WorkoutRoutinesActivity.class);
intent.putExtra(WorkoutRoutinesActivity.EXTRA_WORKOUT_NAME, workoutName);
intent.putExtra(WorkoutRoutinesActivity.EXTRA_WORKOUT_DAYS, workoutDays);
Log.i(TAG, workoutDays.toString());
startActivity(intent);
}
});
}
The problem is not in the intent, but in the way you obtain workoutName (this is the null value). You create the activity, set up final EditText mWorkoutName = (EditText) findViewById(R.id.workout_name1); and then immediately ask for the input value through workoutName = mWorkoutName.getText().toString();, but at this time the user still hasn't entered anything. You should put that second line in the listener below (so its activated only after the user presses mNextButton. It's a good idea to put some check after it and send a message to user that they need to fill in that field (if it is indeed necessary).
Looks like the values for workoutName and workoutDays are not filled in initially when the view is created. You should move retrieving the value from the text fields to your onClickListener function.
you checking the CheckBox and EditText in onCreate, absolutely the EditText will be empty and all CheckBox it not checked

android putextra without start activity

i need help please.
I have two activities and a db. All i want to do is when i press a button in activity A, i send the string in my editText to the activity B. In the activity B i try to insert that string in my db and display it in a listview. All works if i start the activity B in the activity A but i wont display the activity B.
Here my code:
Activity A:
public class Example extends Activity {
public final static String ID_EXTRA2="com.example.activities";
public EditText MyInputText = null;
ImageView MyButton;
TextView MyOutputText, MyInputtext;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.diccionary);
MyInputText = (EditText)findViewById(R.id.InputText);
MyOutputText = (TextView)findViewById(R.id.OutputText);
MyButton = (ImageView)findViewById(R.id.botonaceptar);
MyButton.setOnClickListener(MyButtonOnClickListener);
public ImageView.OnClickListener MyTranslateButtonOnClickListener = new ImageView.OnClickListener(){
public void onClick(View v) {
String InputString;
InputString = MyInputText.getText().toString();
try{
Intent d = new Intent(Example.this, Secondactivity.class);
d.putExtra(ID_EXTRA2, InputString);
//startActivity(d); <----- If i start the secondactivity, that works...
}catch (Exception e){
}
}
};
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater awesome = getMenuInflater();
awesome.inflate(R.menu.main_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.menu1:
startActivity(new Intent("com.example.activities.SECONDACTIVITY"));
return true;
case R.id.menu2:
//something to do
return true;
}
return false;
}
};
Activity B:
public class Secondactivity extends Activity {
NoteAdapter2 adapter = null;
NoteHelper2 helper2 = null;
Cursor dataset_cursor2 = null;
String entriId = null;
public ListView list2;
String passedword = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
try{
list2 = (ListView)findViewById(R.id.list2);
helper2 = new NoteHelper2(this);
---->passedword = getIntent().getStringExtra(Example.ID_EXTRA2);
---->helper2.insert(passedword); //here i insert the string in my db
startManagingCursor(dataset_cursor2);
dataset_cursor2 = helper2.getAll();
adapter = new NoteAdapter2(dataset_cursor2);
list2.setAdapter(adapter);
dataset_cursor2.requery();
adapter.notifyDataSetChanged();
//this is how we know to do when a list item is clicked
list2.setOnItemClickListener(onListClick);
}
catch (Exception e){
// this is the line of code that sends a real error message to the log
Log.e("ERROR", "ERROR IN CODE" + e.toString());
//this is the line that prints out the location in the code where the error ocurred
e.printStackTrace();
}
}
#Override
protected void onDestroy() {
super.onDestroy();
helper2.close();
}
private AdapterView.OnItemClickListener onListClick = new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
entriId = String.valueOf(id);
}
};
class NoteAdapter2 extends CursorAdapter {
NoteAdapter2(Cursor c){
super(Zhistorytranslate.this, c);
}
public void bindView(View row2, Context ctxt, Cursor c) {
NoteHolder2 holder2 = (NoteHolder2)row2.getTag();
holder2.populateFrom2(c, helper2);
}
public View newView(Context ctxt, Cursor c, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row2 = inflater.inflate(R.layout.row2, parent, false);
NoteHolder2 holder2 = new NoteHolder2(row2);
row2.setTag(holder2);
return (row2);
}
}
static class NoteHolder2 {
private TextView entriText = null;
NoteHolder2(View row2){
entriText = (TextView)row2.findViewById(R.id.entri);
}
void populateFrom2(Cursor c, NoteHelper2 helper2) {
entriText.setText(helper2.getEntri(c));
}
}
If I understood you correctly, you want to send data from A to B without launching B. In this case, you need to forget about Intents and consider a way to store data in your app. My suggestion is to use SharedPreferences.
Here is how you can use it:
In your Activity A, store the String:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("string_id", InputString); //InputString: from the EditText
editor.commit();
In your Activity B, you can get the value by:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String data = prefs.getString("string_id", "no id"); //no id: default value
Your question is very difficult to understand, but you seem to want to be able to add the EditText's contents into your database without starting another Activity. Simply do this in your Image's OnClickListener:
public void onClick(View v) {
NoteHelper2 helper2 = new NoteHelper2(this);
helper2.insert(MyInputText.getText().toString());
}
You should also read about Java naming convention.

android, creating/updating view from a method class running in an async task

well i'm having some problem with android. Maybe its simple but i'm pretty new in android world (3, 4 days actually). Well i have an activity whitch runs an asyncTask that stands to reading data from a sensor network. The async Task only executes the function l.read() that by itself is a loop and keep allways "earing" the sensor network and when a new node joins to the sensor network, it tells the UI thread that one more node has joined, and so it has to update the view (witch has just one tab saying that no nodes exists and will now have to have one node available - besides this i even have to load an xml layout file for this tab ) the problem is that, when i preform the function that supostly creates a view and add a tab (that is properly working because when i call it on onCreate it works) the app do not respond anymore, however, Logcat gives me no errors. It look like it works but it is not showing anything.
Please, i dont expect you to read all this code, its just to hel to explain my problem. Its been 2 days and i'm still asking for a solution..
main Activity:
public class PrincipalActivity extends Activity implements OnClickListener
{
private Button Send;
private Button Options;
private TextView ERROR;
private Bundle extras;
private String IP;
private String PORT;
private TabHost tabs;
private ligação l;
View m_vForm;
TabHost tabHost;
CustomView Cview;
ReadsData read;
//constructor
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
CustomView vv = new CustomView(PrincipalActivity.this,0);
setContentView(vv);
//instanciating the objects
IP = new String();
PORT = new String();
extras = getIntent().getExtras();
IP = extras.getString("IP"); //get the IP and port from the previous activity
PORT = extras.getString("PORT");
ERROR = (TextView) findViewById(R.id.ERROR);
tabs = (TabHost) findViewById(R.id.tabhost);
tabs.setup();
Send = (Button) findViewById(R.id.SendCommand);
Send.setOnClickListener(this);
Options = (Button) findViewById(R.id.Options);
Options.setOnClickListener(this);
//=========================
CreateAView("No Nodes",false);
l = new ligação(IP, Integer.parseInt(PORT),this); //CLASS LIGAÇÃO
// RunnableThread rT1 = new RunnableThread("t1",l,this);
read = new ReadsData();
read.execute();
//Textviews (Values)
}
public void AddUpdateNodes(Nodes n,int func)
{
//func is 0 if it it to add a node or 1 if it is to update an existing one
if(func == 0)
{
String s = new String();
s+= n.GETSourceNodeID();
CreateAView(s, true);
Cview.addNewNode(n);
}
if(func == 1)
Cview.UpdateNodeInformation(n);
}
public void onClick(View v)
{
if(v == Send)
{
// if i call CreateAView here it works ok
ERROR.setText(IP);
}
if(v == Options)
{
ERROR.setText(PORT);
}
}
// CREATING A VIEW WITH THE TABS
public void CreateAView(String s,boolean nodesAvailable)
{
m_vForm = createTABForm(s,nodesAvailable);
setContentView(m_vForm);
}
private ViewGroup createTABForm(String s,boolean nodesAvailable1)
{
final boolean nodesAvailable = nodesAvailable1;
// construct the TAB Host
tabHost = new TabHost(this);
tabHost.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT) );
// the tabhost needs a tabwidget, that is a container for the visible tabs
TabWidget tabWidget = new TabWidget(this);
tabWidget.setId(android.R.id.tabs);
tabWidget.setBackgroundColor(Color.BLUE);
tabHost.addView(tabWidget, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) );
// the tabhost needs a frame layout for the views associated with each visible tab
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.setId(android.R.id.tabcontent);
frameLayout.setPadding(0, 65, 0, 0);
tabHost.addView(frameLayout, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) );
// setup must be called if you are not initialising the tabhost from XML
tabHost.setup();
// create the tabs
TabSpec ts = tabHost.newTabSpec("TAB_TAG_2");
ts.setIndicator(s); // creating a tabb with the specified name
ts.setContent(new TabHost.TabContentFactory(){
public View createTabContent(String tag)
{
// -- this tab contains a single control - the listview -- //
Cview = new CustomView(PrincipalActivity.this,nodesAvailable);
return Cview; // IS AN OBJECT FROM THE CLASS CustomView
}
});
tabHost.addTab(ts);
return tabHost;
}
////////////////////////////////////////////////////////////////
//Async Tasks
private class ReadsData extends AsyncTask
{
#Override
protected Object doInBackground(Object... params)
{
l.read();
return null;
}
protected void onPostExecute()
{
l.SocketClosed_();
}
}
}
//CLASS CUSTOM VIEW
public CustomView(Context context,boolean NodesAvailable)
{
super(context);
if(NodesAvailable) //loads a layout
{
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=layoutInflater.inflate(R.layout.finallayout,this);
//only after inflate
ADC0 = (TextView) findViewById(R.id.ADC00);
}
else // loads another layout
{
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=layoutInflater.inflate(R.layout.no_nodes,this);
}
}
public void addNewNode(Nodes n)
{
String s = new String();
s = new String();
s += n.GETSensores(0).GETvalor();
ADC0.setText(s);
}
public void UpdateNodeInformation(Nodes n)
{
String s = new String();
s += n.GETSourceNodeID();
//if(s.equals())
}
}
//SOME CODE OF LIGAÇÃO CLASS
public class ligação
{
protected PrincipalActivity cont;
//Constructors
public ligação(String ss,int Port,PrincipalActivity c){ s=ss; p=Port;cont = c; }
public void read()
{
while(flag)
{
...
cont.AddUpdateNodes(node, 0);
...
}
Many thanks in advance
it's weird that your app doesn't crash , since all UI operations should be done on the UI thread . maybe it's because the asynctask's thread has crashed but not the ui thread , and that's why nothing occurs.
anyway , in order to create/update the view within the asyncTask , you can use any of the following , which will post something to the UI thread to do as soon as it can :
use a handler.
use publishProgress.
use runOnUiThread.

Button to transfer me to next page and start a game

It's hard to explain in the title. Basically as far as I can tell the submit button is taking the name and placing it in the array like I want. What I need now is for the Play(done) Button to transfer the user and the data to the next class (which I believe is coded correctly) and I need it to start a game. The game which you will see in the second class (get the data from the previous) I need it to display the names from the names array 1 at a time and randomly assign them a task to do from the tasks array.
Currently the app is force closing after I click the play button. I'm linking both classes cause I'm pretty sure the problem is in the second class. Thanks for your help ahead of time.
Class1
public class Class1 extends Activity
{
int players=0;
String names[];
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.class1);
final EditText input = (EditText) findViewById(R.id.nameinput);
final ArrayList<String> names = new ArrayList<String>();
Button submitButton = (Button) findViewById(R.id.submit_btn);
submitButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View submit1)
{
players++;
for(int i=0; i < 6; i++)
{
names.add(input.getText().toString());
input.setText("");
}
}
});
Button doneButton = (Button) findViewById(R.id.done_btn);
doneButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View done1)
{
Intent done = new Intent(Class1.this, Game.class);
Bundle bundle = new Bundle();
bundle.putStringArrayList("arrayKey", names);
done.putExtra("players", players);
//done.putExtra("names", names[players]);
startActivity(done);
}
});
}
Game Class
public class Game extends Activity
{
int players, counter=0, score, ptasks,rindex;
String[] names, tasks;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
Bundle bundle = this.getIntent().getExtras();
String[] names = bundle.getStringArray("arrayKey");
Intent game = getIntent();
players = game.getIntExtra("players", 1);
//names = game.getStringArrayExtra("names");
Random generator = new Random();
tasks[0]= "";
tasks[1]= "";
tasks[2]= "";
tasks[3]= "";
tasks[4]= "";
tasks[5]= "";
tasks[6]= "";
tasks[7]= "";
tasks[8]= "";
tasks[9]= "";
while (counter <5)
{
for (int i = 0; i < players; i++)
{
TextView name1 = (TextView) findViewById(R.id.pname);
name1.setText( names[i]+":");
ptasks = 10;
rindex = generator.nextInt(ptasks);
TextView task = (TextView) findViewById(R.id.task);
task.setText( tasks[rindex]);
}
Button failButton = (Button) findViewById(R.id.fail_btn);
failButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View failed)
{
}
});
Button notButton = (Button) findViewById(R.id.notbad_btn);
notButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View notbad)
{
}
});
Button champButton = (Button) findViewById(R.id.champ_btn);
champButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View champp)
{
}
});
counter++;
}
}
Thought I should also mention that these buttons on the 2nd page I would like to assign a score to whichever name array person is up and keep track until the final round where it will display the winner. If anyone has any idea how to make that work.
Have you made sure to include the Game activity as an Application Node in your AndroidManifest?
If not, open your manifest to the application tab, on the bottom hit Add, and add an Activity of the name .Game
Without this, that intent never gets received by the other class.
You've already been told that you use non-initialized arrays here: EditText and using buttons to submit them. But also you're trying to get array extra, however you don't put it inside intent. And you're using uninitialized tasks array in Game class.

Categories

Resources