Reputation: 47
I'm facing an issue regarding intent to my SecondActivity, the main activity is the splash screen which has a progressbar. The progressbar intervals loads fine and when it comes to switching to the next part on moving on to the the secondactivity, i get some errors which are not traceable and are real hectic. Here's my Second Activity's code:
package com.example.waleedmalik.computerparts;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;
public class SecondActivity extends AppCompatActivity {
ToggleButton tb;
Button btn;
public static boolean tbflag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
tb = (ToggleButton)findViewById(R.id.toggleButton1);
btn = (Button)findViewById(android.R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
tbflag = tb.isChecked();
Intent in = new Intent(getApplicationContext(),
GameActivity.class);
startActivity(in);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_second, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Upvotes: 2
Views: 77
Reputation: 357
Change the button initialization like this:
as
btn = (Button)findViewById(android.R.id.button1);
line to
btn = (Button)findViewById(R.id.button1);
Upvotes: 4