2014-07-09 2 views
0

SwipeRefreshLayout으로 내 앱을 실행하면 앱이 중단됩니다. 나는이 문제를 디버깅하는 것을 시도했다, 그러나 setColorScheme이있는이 ensureLayoutSwipeRefreshLayout으로 인해 onCreate에서 NullPointerException이 발생합니다.

에 로그 캣 이동 후 발생하는 것 같습니다 :

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 


    SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); 
    swipeLayout.setOnRefreshListener(new OnRefreshListener() { 

     @Override 
     public void onRefresh() { 
      // TODO Auto-generated method stub 

     } 
    }); 
    swipeLayout.setColorScheme(Color.RED, Color.BLUE, Color.GREEN, 
      Color.YELLOW); 

} 

내 XAML 다음은

07-09 16:46:56.093: E/AndroidRuntime(18659): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.heath_bar.twitter/com.heath_bar.twitter.MainActivity}: java.lang.NullPointerException 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2328) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.app.ActivityThread.access$900(ActivityThread.java:169) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.os.Handler.dispatchMessage(Handler.java:102) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.os.Looper.loop(Looper.java:136) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.app.ActivityThread.main(ActivityThread.java:5476) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at java.lang.reflect.Method.invokeNative(Native Method) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at java.lang.reflect.Method.invoke(Method.java:515) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at dalvik.system.NativeStart.main(Native Method) 
07-09 16:46:56.093: E/AndroidRuntime(18659): Caused by: java.lang.NullPointerException 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.support.v4.widget.SwipeRefreshLayout.ensureTarget(SwipeRefreshLayout.java:293) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.support.v4.widget.SwipeRefreshLayout.setColorScheme(SwipeRefreshLayout.java:268) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at com.heath_bar.twitter.MainActivity.onCreate(MainActivity.java:56) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.app.Activity.performCreate(Activity.java:5451) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
07-09 16:46:56.093: E/AndroidRuntime(18659): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) 
07-09 16:46:56.093: E/AndroidRuntime(18659): ... 11 more 

내 코드입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/swipe_container" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<ScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <TableLayout 
     android:id="@+id/table" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" /> 
</ScrollView> 
</android.support.v4.widget.SwipeRefreshLayout> 

이것이 충돌하는 이유는 무엇입니까? 안드로이드 비공개 라이브러리의 프로젝트에 올바른 jar 파일을 추가했습니다.

enter image description here

모든 아이디어는 크게 감사하고 있습니다. 미리 감사드립니다.

답변

1

어디에 문제가 있었는지는 확실하지 않지만 android.support.v4 버전 20.0은 19.1이 아니지만 다소 이상한 이유로 setColorScheme은 (20.0 에서처럼) deprecated로 표시되지 않았습니다. 라이브러리를 삭제하고 android.support.v4 라이브러리 버전 20.0을 다시 추가하십시오. 그런 다음 setColorScheme을 변경하여 setColorSchemeColors으로 설정하여 문제를 해결하십시오.

다른 사람이 시간을 절약 할 수 있기를 바랍니다.

1

답은 swipeRefreshLayout이 이미 childView를 추가 한 후에 setColorScheme을 설정해야한다는 것입니다. 시도 해봐!

관련 문제