2013年9月5日星期四

intent to pass an error but no error message click on the button to exit

mainactivity
package com.example.intent1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
private Button myButton = null;
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
myButton = (Button) findViewById (R.id.myButton);
myButton.setOnClickListener (new MyButtonListener ());
}
class MyButtonListener implements OnClickListener {

@ Override
public void onClick (View v) {
/ / TODO Auto- generated method stub
Intent intent = new Intent ();
intent.setClass (MainActivity.this, Mudi.class);
MainActivity.this.startActivity (intent);
}

}

@ Override
public boolean onCreateOptionsMenu (Menu menu) {
/ / Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater (). inflate (R.menu.main, menu);
return true;
}

}
mudiactivity
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import android.widget.TextView;

public class Mudi extends Activity {
@ SuppressLint ("NewApi")
private TextView myTextView = null;
@ TargetApi (Build.VERSION_CODES.HONEYCOMB)
@ SuppressLint ("NewApi")
@ Override
protected void onCreate (Bundle savedInstanceState) {
/ / TODO Auto- generated method stub
super.onCreate (savedInstanceState);
setContentView (R.layout.mudi);
myTextView = (TextView) findViewById (R.id.myTextView);
myTextView.setText (R.string.hello_world);
if (Build.VERSION.SDK_INT> = Build.VERSION_CODES.HONEYCOMB) {
/ / Show the Up button in the action bar.
getActionBar (). setDisplayHomeAsUpEnabled (true);
}
}
@ TargetApi (Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar () {
if (Build.VERSION.SDK_INT> = Build.VERSION_CODES.HONEYCOMB) {
getActionBar (). setDisplayHomeAsUpEnabled (true);
}
}
@ Override
public boolean onOptionsItemSelected (MenuItem item) {
switch (item.getItemId ()) {
case android.R.id.home:
/ / This ID represents the Home or Up button. In the case of this
/ / activity, the Up button is shown. Use NavUtils to allow users
/ / to navigate up one level in the application structure. For
/ / more details, see the Navigation pattern on Android Design:
/ /
/ / http://developer.android.com/design/patterns/navigation.html # up-vs-back
/ /
NavUtils.navigateUpFromSameTask (this);
return true;
}
return super.onOptionsItemSelected (item);
}



}
manifest.xml
android: minSdkVersion = "8"
android: targetSdkVersion = "17" />

android: allowBackup = "true"
android: icon = "@ drawable / ic_launcher"
android: label = "@ string / app_name"
android: theme = "@ style / AppTheme">
android: name = "com.example.intent1.MainActivity"
android: label = "@ string / app_name">






;



Click the button to stop running after run , forced to exit the application , look at where the error , syntax error estimate what not, because the editors did not prompt any error after enter the main activity is normal, just click the button after error , exit the application

------ Solution ------------------------------------ --------
log it, paste the error message view
------ Solution --------------------- -----------------------


public class Mudi extends Activity {

inconsistent definitions
------ For reference only -------------------------------- -------
- admire so much patience to carefully look at this · · · ·
------ For reference only ------ ---------------------------------
entirely correct, they are not careful , Thank you very much , plus the < br>

没有评论:

发表评论