我正在尝试实现3D过渡效果。最后我得到了一个null pointer exception and Fatal signal 6 (SIGABRT) at 0x000009e7 (code=-6)
。下面我发布了堆栈跟踪并指出错误行。
堆栈跟踪:
12-05 01:51:25.672: W/System.err(2535): java.lang.NullPointerException
12-05 01:51:25.692: W/System.err(2535): at info.androidhive.tabsswipe.fragment.ActivitySwitcher.apply3DRotation(ActivitySwitcher.java:84)
12-05 01:51:25.692: W/System.err(2535): at info.androidhive.tabsswipe.fragment.ActivitySwitcher.animationOut(ActivitySwitcher.java:50)
12-05 01:51:25.692: W/System.err(2535): at info.androidhive.tabsswipe.fragment.MainActivity$SampleWebViewClient.shouldOverrideUrlLoading(StackOverflow.java:74)
12-05 01:51:25.692: W/System.err(2535): at com.android.webview.chromium.WebViewContentsClientAdapter.shouldOverrideUrlLoading(WebViewContentsClientAdapter.java:293)
12-05 01:51:25.702: W/System.err(2535): at com.android.org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(AwContentsClientBridge.java:96)
12-05 01:51:25.702: W/System.err(2535): at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
12-05 01:51:25.702: W/System.err(2535): at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27)
12-05 01:51:25.702: W/System.err(2535): at android.os.Handler.dispatchMessage(Handler.java:102)
12-05 01:51:25.702: W/System.err(2535): at android.os.Looper.loop(Looper.java:136)
12-05 01:51:25.712: W/System.err(2535): at android.app.ActivityThread.main(ActivityThread.java:5017)
12-05 01:51:25.712: W/System.err(2535): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 01:51:25.712: W/System.err(2535): at java.lang.reflect.Method.invoke(Method.java:515)
12-05 01:51:25.712: W/System.err(2535): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
12-05 01:51:25.712: W/System.err(2535): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
12-05 01:51:25.712: W/System.err(2535): at dalvik.system.NativeStart.main(Native Method)
12-05 01:51:25.772: A/libc(2535): Fatal signal 6 (SIGABRT) at 0x000009e7 (code=-6), thread 2535 (dhive.tabsswipe)
ActivitySwitcher.java:
public class ActivitySwitcher {
private final static int DURATION = 300;
private final static float DEPTH = 400.0f;
/* ----------------------------------------------- */
public interface AnimationFinishedListener {
/**
* Called when the animation is finished.
*/
public void onAnimationFinished();
}
/* ----------------------------------------------- */
public static void animationIn(View container, WindowManager windowManager) {
animationIn(container, windowManager, null);
}
public static void animationIn(View container, WindowManager windowManager,
AnimationFinishedListener listener) {
apply3DRotation(90, 0, false, container, windowManager, listener);
}
public static void animationOut(View container, WindowManager windowManager) {
animationOut(container, windowManager, null);
}
public static void animationOut(View container,
WindowManager windowManager, AnimationFinishedListener listener) {
apply3DRotation(0, -90, true, container, windowManager, listener); ----> 50th line
}
/* ----------------------------------------------- */
private static void apply3DRotation(float fromDegree, float toDegree,
boolean reverse, View container, WindowManager windowManager,
final AnimationFinishedListener listener) {
Display display = windowManager.getDefaultDisplay();
final float centerX = display.getWidth() / 2.0f;
final float centerY = display.getHeight() / 2.0f;
final Rotate3dAnimation a = new Rotate3dAnimation(fromDegree, toDegree,
centerX, centerY, DEPTH, reverse);
a.reset();
a.setDuration(DURATION);
a.setFillAfter(true);
a.setInterpolator(new AccelerateInterpolator());
if (listener != null) {
a.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
listener.onAnimationFinished();
}
});
}
container.clearAnimation(); --->84th line error
container.startAnimation(a);
}
}
MainActivity.java: (已编辑)
public class MainActivity extends Fragment implements OnRefreshListener{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_activity,
container, false);
return rootView;
}
private class SampleWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("stac", url);
if (url.equals("file:///android_asset/first.html")) {
view.loadUrl(url);
return true;
} else {
Log.d("stacelse", url);
final Intent i = new Intent(getActivity(), Sample1.class);
i.putExtra("url", url);
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
ActivitySwitcher.animationOut(getActivity().findViewById(R.id.container),
getActivity().getWindowManager(),
new ActivitySwitcher.AnimationFinishedListener() {
@Override
public void onAnimationFinished() {
Log.d("Intent Check","First Check"+i);
startActivity(i);
}
});
Log.d("Intent Check","Second Check"+i);
startActivity(i);
getActivity().overridePendingTransition(R.anim.fade_out,
R.anim.slide_down);
return true;
}
}
}
我无法解决这个问题。任何人都可以帮我解决这个问题。谢谢。
答案 0 :(得分:0)
第84行:
`container` must be null
所以,在第50行:
`container` must be null
所以看起来getActivity().findViewById(R.id.container)
中的shouldOverrideUrlLoading
返回null。你检查了它的价值吗?