2016-11-10 54 views
-1

當我在摩托羅拉Nexus 6上運行我的應用程序時,我得到NullPointerException.Problem與一個TextView和設置文本相同。我看到一些在線解決方案,但沒有一個爲我工作。在不同的智能手機上使用JVM,或者嵌套在活動中的片段的生命週期。大屏幕設備上的NullPointerException

一切工作正常在較小的設備上。

登錄波紋管:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com..data.models.entity.Email.getUsername()' on a null object reference 
                at com..presenter.view.fragment.ForgotPasswordFragmentComplete.onStart(ForgotPasswordFragmentComplete.java:84) 

這裏是我的片段:

@Bind(R.id.button_resend_email) 
    AppCompatButton resendEmail; 
    @Bind(R.id.resend_user_email)AutoResizeTextView resendEmailTxt; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     DaggerForgotPasswordCompletedComponent.builder() 
       .applicationComponent(
         ((AndroidApplication) getActivity().getApplication()).getApplicationComponent()) 
       .forgotPasswordCompletedModule(new ForgotPasswordCompletedModule()) 
       .build() 
       .inject(this); 


    } 

    @Override 
    public void onStart() { 
     super.onStart(); 

     realm = getRealm(); 
     RealmQuery<Email> query1 = realm.where(Email.class); 
     Email result1 = query1.findFirst(); 

     resendEmailTxt = (AutoResizeTextView) getView().findViewById(R.id.resend_user_email) ; 

     this.resendEmailTxt.setText(result1.getUsername()); 

    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
     realm.close(); 


    } 



    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 

     return inflater.inflate(R.layout.fragment_forgot_password_fragment_complete, container, false); 


    } 


    @Override 
    protected int getFragmentLayoutId() { 
     return R.layout.fragment_forgot_password_fragment_complete; 
    } 
+2

沒有意義,這是屏幕相關。 getRealm()的外觀是什麼? – zgc7009

+0

在Samsung Galaxy S4上,一切正常。它只是獲得Realm實例和初始化。 –

回答

1

如果你nullPointerException這可能意味着你的result1變量沒有被賦值。這意味着你的query1.findFirst()可能沒有任何回報。

+0

query1,findFirst正在返回正確的東西,已經檢查與Log.And它在星系s4上工作正常。 –

+0

@AnonimoAnonimus您的問題中的例外情況另有說明。 – 4castle

+0

檢查[this](http://stackoverflow.com/questions/31366061/app-crahes-in-different-devices)鏈接,它似乎與您的問題類似。 – DarkCygnus

0

嘗試你的代碼擺脫onStart()onResume()