Should I make a toString() method there? 
Also, if I try something like this, I get the same NPE.: 

transactionsList.setCellFactory(new Callback<ListView<Transaction>, 
ListCell<Transaction>>() {
    @Override
    public ListCell<Transaction> call(ListView<Transaction> param) {
        return new TextFieldListCell<Transaction>(new 
StringConverter<Transaction>() {
            @Override
            public String toString(Transaction tx) {
                Coin value = tx.getValue(Main.bitcoin.wallet());
                if(value.isPositive()) {
                    
                    Address sender_address = null;
                    for(TransactionInput tx_in : tx.getInputs()){
                        if(!tx_in.isCoinBase()){
                            
                            
sender_address=tx_in.getConnectedOutput().getScriptPubKey().getToAddress(MainNetParams.get());


                        }
                    }
                    return "Incoming payment of 
"+MonetaryFormat.BTC.format(value) + " from: " + sender_address ;
                }

I'm using IntelliJ IDEA and when I use getScriptPubKey() it shows me this 
message: 

Method invocation 'getScriptPubKey' may produce 'NullPointerException' 

I don't know if this might be useful to know if the problem comes from my code, 
I just modified the wallettemplate.MainController class to check how 
inputs/outputs work and I haven't done anything to the transaction "tx".

 

El lunes, 11 de marzo de 2019, 19:28:25 (UTC+1), Andreas Schildbach 
escribió:
>
> The NPE is happening in your own code. 
>
> Bitcoinj 0.14.7 doesn't have a method 
> wallettemplate.MainController$1$1.toString(). 
>
> Maybe tx_out is null? TransactionOutput.getScriptPubKey() can hardly be 
> null, since an instance is created there and returned. 
>
>
> On 11/03/2019 12.39, J wrote: 
> > 0.14.7 
> > 
> > El lunes, 11 de marzo de 2019, 12:32:34 (UTC+1), Andreas Schildbach 
> > escribió: 
> > 
> >     Also, what version of bitcoinj are you using? 
> > 
> > 
> >     On 11/03/2019 10.02, J wrote: 
> >     > This is the exception: 
> >     > java.lang.NullPointerException 
> >     > at 
> >     wallettemplate.MainController$1$1.toString(MainController.java:109) 
> >     > at 
> wallettemplate.MainController$1$1.toString(MainController.java:99) 
> >     > at 
> >     javafx.scene.control.cell.CellUtils.getItemText(CellUtils.java:100) 
> >     > at 
> javafx.scene.control.cell.CellUtils.updateItem(CellUtils.java:201) 
> >     > at 
> >     > 
> >     
> javafx.scene.control.cell.TextFieldListCell.updateItem(TextFieldListCell.java:201)
>  
>
> > 
> >     > at javafx.scene.control.ListCell.updateItem(ListCell.java:471) 
> >     > at javafx.scene.control.ListCell.lambda$new$41(ListCell.java:167) 
> >     > at 
> >     > 
> >     
> javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
>  
>
> > 
> >     > at 
> >     > 
> >     
> com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
>  
>
> > 
> >     > at 
> >     > 
> >     
> com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
>  
>
> > 
> >     > at 
> >     > 
> >     
> javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233) 
>
> > 
> >     > at 
> >     
> javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482) 
> >     > at 
> >     > 
> >     
> javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541) 
> > 
> >     > at 
> >     > 
> >     
> javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205) 
>
> > 
> >     > at 
> >     > 
> >     
> javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:113)
>  
>
> > 
> >     > at 
> >     > 
> >     
> com.sun.javafx.binding.ContentBinding$ListContentBinding.onChanged(ContentBinding.java:117)
>  
>
> > 
> >     > at 
> >     > 
> >     
> com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
>  
>
> > 
> >     > at 
> >     > 
> >     
> com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
>  
>
> > 
> >     > at 
> >     > 
> >     
> javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233) 
>
> > 
> >     > at 
> >     
> javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482) 
> >     > at 
> >     > 
> >     
> javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541) 
> > 
> >     > at 
> >     > 
> >     
> javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205) 
>
> > 
> >     > at 
> >     > 
> >     
> javafx.collections.ModifiableObservableListBase.setAll(ModifiableObservableListBase.java:90)
>  
>
> > 
> >     > at 
> wallettemplate.utils.BitcoinUIModel.update(BitcoinUIModel.java:68) 
> >     > at 
> >     
> wallettemplate.utils.BitcoinUIModel.access$100(BitcoinUIModel.java:39) 
> >     > at 
> >     > 
> >     
> wallettemplate.utils.BitcoinUIModel$1.onWalletChanged(BitcoinUIModel.java:58) 
>
> > 
> >     > at org.bitcoinj.wallet.Wallet$4.run(Wallet.java:2919) 
> >     > at 
> >     > 
> >     
> com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
>  
>
> > 
> >     > at java.security.AccessController.doPrivileged(Native Method) 
> >     > at 
> >     > 
> >     
> com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
>  
>
> > 
> >     > at 
> >     > 
> >     
> com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
>  
>
> > 
> >     > at 
> >     com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native 
> >     > Method) 
> >     > at 
> >     > 
> >     
> com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:204)
>  
>
> > 
> >     > at 
> >     
> com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:511) 
> >     > at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107) 
> >     > at 
> >     > 
> >     
> com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:590)
>  
>
> > 
> >     > at javafx.stage.Stage.showAndWait(Stage.java:474) 
> >     > at wallettemplate.utils.GuiUtils.runAlert(GuiUtils.java:52) 
> >     > at 
> >     wallettemplate.utils.GuiUtils.lambda$crashAlert$1(GuiUtils.java:63) 
> >     > at wallettemplate.utils.GuiUtils.crashAlert(GuiUtils.java:67) 
> >     > at 
> >     > 
> >     
> wallettemplate.utils.GuiUtils.lambda$handleCrashesOnThisThread$2(GuiUtils.java:75)
>  
>
> > 
> >     > at 
> com.sun.glass.ui.Application.reportException(Application.java:453) 
> >     > at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
> >     > at 
> >     > 
> >     
> com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177) 
>
> > 
> >     > at java.lang.Thread.run(Thread.java:748) 
> >     > 
> >     > and this is the piece of code: 
> >     > 
> >     > tx_out.getScriptPubKey().getToAddress(MainNetParams.get());    
> >      //tx_out 
> >     > is one of the outputs of the transaction 
> >     > 
> >     > El lunes, 11 de marzo de 2019, 2:27:45 (UTC+1), Andreas Schildbach 
> >     escribió: 
> >     > 
> >     >     Can you post the exception and the piece of code you're using? 
> >     Also, 
> >     >     what version of bitcoinj are you using? 
> >     > 
> >     > 
> >     >     On 10/03/2019 20.04, J wrote: 
> >     >     > When trying to get the address of an output, if I call the 
> >     method 
> >     >     > getScriptPubKey() I always get a null pointer exception.  
> >     >     > I checked this 
> >     >     > 
> >     >     
> >     <
> https://groups.google.com/forum/#!msg/bitcoinj/27k8xsf29Dw/WRA6csmm-vEJ 
> >     <
> https://groups.google.com/forum/#!msg/bitcoinj/27k8xsf29Dw/WRA6csmm-vEJ> 
> > 
> >     >     
> >     <
> https://groups.google.com/forum/#!msg/bitcoinj/27k8xsf29Dw/WRA6csmm-vEJ 
> >     <
> https://groups.google.com/forum/#!msg/bitcoinj/27k8xsf29Dw/WRA6csmm-vEJ>>> 
> and 
>
> > 
> >     > 
> >     >     > this 
> >     >     > 
> >     >     
> >     <
> https://bitcoin.stackexchange.com/questions/2370/how-to-get-destination-address-from-bitcoinj-transactionoutput
>  
> >     <
> https://bitcoin.stackexchange.com/questions/2370/how-to-get-destination-address-from-bitcoinj-transactionoutput>
>  
>
> > 
> >     >     
> >     <
> https://bitcoin.stackexchange.com/questions/2370/how-to-get-destination-address-from-bitcoinj-transactionoutput
>  
> >     <
> https://bitcoin.stackexchange.com/questions/2370/how-to-get-destination-address-from-bitcoinj-transactionoutput>>>,
>  
>
> > 
> >     > 
> >     >     > but seems unsolved and the link to the github repository on 
> >     >     > StackExchange is not working. 
> >     >     > I tried checking if the transaction is coinbase first, but 
> >     still the 
> >     >     > same error. 
> >     >     > 
> >     >     > Any ideas on how to solve this?  
> >     >     > 
> >     >     > -- 
> >     >     > You received this message because you are subscribed to the 
> >     Google 
> >     >     > Groups "bitcoinj" group. 
> >     >     > To unsubscribe from this group and stop receiving emails 
> >     from it, 
> >     >     send 
> >     >     > an email to bitcoinj+u...@googlegroups.com 
> >     >     > <mailto:bitcoinj+u...@googlegroups.com>. 
> >     >     > For more options, visit https://groups.google.com/d/optout 
> >     <https://groups.google.com/d/optout> 
> >     >     <https://groups.google.com/d/optout 
> >     <https://groups.google.com/d/optout>>. 
> >     > 
> >     > 
> >     > -- 
> >     > You received this message because you are subscribed to the Google 
> >     > Groups "bitcoinj" group. 
> >     > To unsubscribe from this group and stop receiving emails from it, 
> >     send 
> >     > an email to bitcoinj+u...@googlegroups.com 
> >     > <mailto:bitcoinj+u...@googlegroups.com>. 
> >     > For more options, visit https://groups.google.com/d/optout 
> >     <https://groups.google.com/d/optout>. 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "bitcoinj" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to bitcoinj+u...@googlegroups.com <javascript:> 
> > <mailto:bitcoinj+u...@googlegroups.com <javascript:>>. 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"bitcoinj" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bitcoinj+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to