这里是日志,我在AVD中收到消息 - 不幸的是已经停止了,请帮我解决这个错误,我想在android中学到更多但是被这个错误所吸引!
07-09 23:47:26.270: D/dalvikvm(831): Not late-enabling CheckJNI (already on)
07-09 23:47:29.460: I/Choreographer(831): Skipped 100 frames! The application may be doing too much work on its main thread.
07-09 23:47:30.160: D/gralloc_goldfish(831): Emulator without GPU emulation detected.
07-09 23:47:56.200: D/WiFiChangeBroadcastReceiver(831): WiFi Status Changed
07-09 23:47:56.530: D/WiFiChangeBroadcastReceiver(831): WiFi Status Changed
07-09 23:48:45.670: I/Choreographer(831): Skipped 222 frames! The application may be doing too much work on its main thread.
07-09 23:48:45.810: I/Choreographer(831): Skipped 39 frames! The application may be doing too much work on its main thread.
07-09 23:48:45.980: I/Choreographer(831): Skipped 212 frames! The application may be doing too much work on its main thread.
07-09 23:48:50.760: I/Choreographer(831): Skipped 190 frames! The application may be doing too much work on its main thread.
07-09 23:48:53.120: D/AndroidRuntime(831): Shutting down VM
07-09 23:48:53.120: W/dalvikvm(831): threadid=1: thread exiting with uncaught exception (group=0xb2aeaba8)
07-09 23:48:53.130: E/AndroidRuntime(831): FATAL EXCEPTION: main
07-09 23:48:53.130: E/AndroidRuntime(831): Process: com.example.beaglem, PID: 831
07-09 23:48:53.130: E/AndroidRuntime(831): java.lang.RuntimeException: Unable to pause activity {com.example.beaglem/com.example.beaglem.FullscreenActivity}: java.lang.NullPointerException
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3062)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3017)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2995)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.access$1000(ActivityThread.java:135)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.os.Handler.dispatchMessage(Handler.java:102)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.os.Looper.loop(Looper.java:136)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-09 23:48:53.130: E/AndroidRuntime(831): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 23:48:53.130: E/AndroidRuntime(831): at java.lang.reflect.Method.invoke(Method.java:515)
07-09 23:48:53.130: E/AndroidRuntime(831): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-09 23:48:53.130: E/AndroidRuntime(831): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-09 23:48:53.130: E/AndroidRuntime(831): at dalvik.system.NativeStart.main(Native Method)
07-09 23:48:53.130: E/AndroidRuntime(831): Caused by: java.lang.NullPointerException
07-09 23:48:53.130: E/AndroidRuntime(831): at com.example.beaglem.FullscreenActivity.onPause(FullscreenActivity.java:185)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.Activity.performPause(Activity.java:5335)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3048)
07-09 23:48:53.130: E/AndroidRuntime(831): ... 12 more
07-09 23:57:25.030: D/gralloc_goldfish(1132): Emulator without GPU emulation detected.
07-09 23:57:25.490: I/Choreographer(1132): Skipped 297 frames! The application may be doing too much work on its main thread.
07-09 23:57:25.660: I/Choreographer(1132): Skipped 200 frames! The application may be doing too much work on its main thread.
07-09 23:47:26.270: D/dalvikvm(831): Not late-enabling CheckJNI (already on)
07-09 23:47:29.460: I/Choreographer(831): Skipped 100 frames! The application may be doing too much work on its main thread.
07-09 23:47:30.160: D/gralloc_goldfish(831): Emulator without GPU emulation detected.
07-09 23:47:56.200: D/WiFiChangeBroadcastReceiver(831): WiFi Status Changed
07-09 23:47:56.530: D/WiFiChangeBroadcastReceiver(831): WiFi Status Changed
07-09 23:48:45.670: I/Choreographer(831): Skipped 222 frames! The application may be doing too much work on its main thread.
07-09 23:48:45.810: I/Choreographer(831): Skipped 39 frames! The application may be doing too much work on its main thread.
07-09 23:48:45.980: I/Choreographer(831): Skipped 212 frames! The application may be doing too much work on its main thread.
07-09 23:48:50.760: I/Choreographer(831): Skipped 190 frames! The application may be doing too much work on its main thread.
07-09 23:48:53.120: D/AndroidRuntime(831): Shutting down VM
07-09 23:48:53.120: W/dalvikvm(831): threadid=1: thread exiting with uncaught exception (group=0xb2aeaba8)
07-09 23:48:53.130: E/AndroidRuntime(831): FATAL EXCEPTION: main
07-09 23:48:53.130: E/AndroidRuntime(831): Process: com.example.beaglem, PID: 831
07-09 23:48:53.130: E/AndroidRuntime(831): java.lang.RuntimeException: Unable to pause activity {com.example.beaglem/com.example.beaglem.FullscreenActivity}: java.lang.NullPointerException
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3062)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3017)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2995)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.access$1000(ActivityThread.java:135)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.os.Handler.dispatchMessage(Handler.java:102)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.os.Looper.loop(Looper.java:136)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-09 23:48:53.130: E/AndroidRuntime(831): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 23:48:53.130: E/AndroidRuntime(831): at java.lang.reflect.Method.invoke(Method.java:515)
07-09 23:48:53.130: E/AndroidRuntime(831): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-09 23:48:53.130: E/AndroidRuntime(831): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-09 23:48:53.130: E/AndroidRuntime(831): at dalvik.system.NativeStart.main(Native Method)
07-09 23:48:53.130: E/AndroidRuntime(831): Caused by: java.lang.NullPointerException
07-09 23:48:53.130: E/AndroidRuntime(831): at com.example.beaglem.FullscreenActivity.onPause(FullscreenActivity.java:185)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.Activity.performPause(Activity.java:5335)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233)
07-09 23:48:53.130: E/AndroidRuntime(831): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3048)
07-09 23:48:53.130: E/AndroidRuntime(831): ... 12 more
07-09 23:57:25.030: D/gralloc_goldfish(1132): Emulator without GPU emulation detected.
07-09 23:57:25.490: I/Choreographer(1132): Skipped 297 frames! The application may be doing too much work on its main thread.
07-09 23:57:25.660: I/Choreographer(1132): Skipped 200 frames! The application may be doing too much work on its main thread.
这是我的主要java
' private static final boolean AUTO_HIDE = true;
/**
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
* user interaction before hiding the system UI.
*/
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
/**
* If set, will toggle the system UI visibility upon interaction. Otherwise,
* will show the system UI visibility upon interaction.
*/
private static final boolean TOGGLE_ON_CLICK = true;
/**
* The flags to pass to {@link SystemUiHider#getInstance}.
*/
private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
/**
* The instance of the {@link SystemUiHider} for this activity.
*/
private SystemUiHider mSystemUiHider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
final View controlsView = findViewById(R.id.fullscreen_content_controls);
final View contentView = findViewById(R.id.fullscreen_content);
// Set up an instance of SystemUiHider to control the system UI for
// this activity.
mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
mSystemUiHider.setup();
mSystemUiHider
.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
// Cached values.
int mControlsHeight;
int mShortAnimTime;
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void onVisibilityChange(boolean visible) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
// If the ViewPropertyAnimator API is available
// (Honeycomb MR2 and later), use it to animate the
// in-layout UI controls at the bottom of the
// screen.
if (mControlsHeight == 0) {
mControlsHeight = controlsView.getHeight();
}
if (mShortAnimTime == 0) {
mShortAnimTime = getResources().getInteger(
android.R.integer.config_shortAnimTime);
}
controlsView.animate()
.translationY(visible ? 0 : mControlsHeight)
.setDuration(mShortAnimTime);
} else {
// If the ViewPropertyAnimator APIs aren't
// available, simply show or hide the in-layout UI
// controls.
controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
}
if (visible && AUTO_HIDE) {
// Schedule a hide().
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
}
});
// Set up the user interaction to manually show or hide the system UI.
contentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (TOGGLE_ON_CLICK) {
mSystemUiHider.toggle();
} else {
mSystemUiHider.show();
}
}
});
// Upon interacting with UI controls, delay any scheduled hide()
// operations to prevent the jarring behavior of controls going away
// while interacting with the UI.
//findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Trigger the initial hide() shortly after the activity has been
// created, to briefly hint to the user that UI controls
// are available.
delayedHide(100);
}
// --------------------------------------------- ------------------------------- //
MediaPlayer playMusic;
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
//To check the Network Name or other info:
//WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
//WifiInfo wifiInfo = wifiManager.getConnectionInfo();
//int ipAddress = wifiInfo.getIpAddress();
// @SuppressWarnings("deprecation")
//String ipaddress = Formatter.formatIpAddress(ipAddress);
//{
//try{
//if("192.168.0.150".equals(ipaddress) );
//try
//{
//playMusic = new MediaPlayer();
//playMusic.setDataSource("http://192.168.0.134/audio/bbb1.php");
// playMusic.setOnPreparedListener(OnPreparedListener) this);
// playMusic = MediaPlayer.create(this, R.raw.testing);
// playMusic.prepare();
// playMusic.start();
}
//}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
playMusic.release();
}
/**
* Touch listener to use for in-layout UI controls to delay hiding the
* system UI. This is to prevent the jarring behavior of controls going away
* while interacting with activity UI.
*/
View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (AUTO_HIDE) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
Handler mHideHandler = new Handler();
Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
mSystemUiHider.hide();
}
};
/**
* Schedules a call to hide() in [delay] milliseconds, canceling any
* previously scheduled calls.
*/
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
} '
答案 0 :(得分:1)
原因是除了onPause方法中的playMusic
代码之外,您已将所有playMusic.release()
代码注释掉了。你应该能够注释掉那一行并让它发挥作用。
如果您查看Log Cat文件中的堆栈跟踪,您将看到以下行:
07-09 23:48:53.130: E/AndroidRuntime(831): at com.example.beaglem.FullscreenActivity.onPause(FullscreenActivity.java:185)
这一行告诉我Null Pointer Exception正在发生的地方(并且看着你的代码显然playMusic
永远不会被设置,因此它是空的。)