MainActivity click a button on the page to achieve the OtherActivity jump.
last error if the resource does not exist.
code is as follows:
public class MainActivity extends Activity {
private Button myButton = null; @ Override
protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main_layout);
myButton = (Button) findViewById (R.id.myButton); myButton.setText ("This is a button"); myButton.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) { / / TODO Auto-generated method stub
Intent intent = new Intent (); intent.setClass (MainActivity.this, OtherActivity.class); / / Perform the following steps before are correct.
MainActivity.this.startActivity (intent); }
}); }
}
OtherActivity in
public class OtherActivity extends Activity { @ Override
protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main_layout);
TextView textView = (TextView) findViewById (R.id.title); textView.setText ("This is the jump page with the title");
Intent intent = getIntent (); String stringExtra = intent.getStringExtra ("test");
TextView othertextView = (TextView) findViewById (R.id.otherTextView); othertextView.setText ("This is the jump to the Activity"); }
}
XML document declaration:
android: minSdkVersion = "17" android: targetSdkVersion = "17" />
android: allowBackup = "true" android: icon = "@ drawable / ic_launcher" android: label = "@ string / app_name" android: theme = "@ style / AppTheme"> android: name = "com.activity.MainActivity" android: label = "@ string / app_name">
------ Solution ------------------------------------ --------
light so see no problem, look at what has gone wrong in logcat, stickers
------ Solution ------------ --------------------------------
best to look at the wrong Tieshanglai:
You can look under OtherActivity this document and MainActivity this document is not placed in the same package below
yes, then clear what works, and then deploy next see them.
If there is wrong, then put it inside using activity_main_layout OtherActivity this layout controls are removed, one by one to see which control what is out of the question
------ Solution --------------------------------------------
you Inside lay a log oncreate it?
------ Solution ---------------------------------------- ----
You can also put code are sent over to help you tune
------ For reference only -------------------- -------------------
have tried, it seems that this is not the reason. .
Another logcat inside just record to a line does not move, did not find a clear error message. .
------ For reference only -------------------------------------- -
OtherActivity in String stringExtra = intent.getStringExtra ("test");?? MainActivity you want to set the value
------ For reference only ----- ----------------------------------
not in this issue, this sentence can deleted.
Originally MainActivity before the value is added, upload code has nothing to do with the problem deleted. This statement can also be deleted
没有评论:
发表评论