Note that there are some explanatory texts on larger screens.

plurals
  1. PONull pointer exception when trying to fetch all documents from CouchDB database using ektorp on Android
    text
    copied!<p>I have simple item model with name and quantity:</p> <pre><code>public class Item extends CouchDbDocument{ private static final long serialVersionUID = -3645214415410443346L; private String name; private int quantity; public Item (String name, int qty){ this.name = name; this.quantity = qty; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getQuantity() { return quantity; } public void setQuantity(int quantity) { this.quantity = quantity; } } </code></pre> <p>and an Item Repository class</p> <pre><code>public class ItemRepository extends CouchDbRepositorySupport&lt;Item&gt;{ public ItemRepository(CouchDbConnector db) { super(Item.class, db); initStandardDesignDocument(); } @GenerateView @Override public List&lt;Item&gt; getAll() { ViewQuery q = createQuery("all").descending(true); return db.queryView(q, Item.class); } </code></pre> <p>and an Item Controller</p> <pre><code>public class ItemController { ItemRepository itemRepository; public String viewAll() { List&lt;Item&gt; items = itemRepository.getAll(); return items.toString(); } } </code></pre> <p>I have a CouchDBConnector class which is added as javascript interface:</p> <pre><code>public class CouchDBConnector { private WebView webView; private DroidGap droidGap; private CouchDbConnector db ; private CouchDbInstance dbInstance; private ItemController itemController; private ItemRepository repo; public CouchDBConnector(DroidGap gap, WebView view) { this.webView = view; this.droidGap = gap; } public void init(){ HttpClient httpClient = new StdHttpClient.Builder() .host("localhost") .port(5984) .build(); dbInstance = new StdCouchDbInstance(httpClient); db = new StdCouchDbConnector("itemdatabase", dbInstance); repo = new ItemRepository(db); itemController = new ItemController(); } public String getAllItems(){ String prefix = "Items \n"; return prefix + repo.getAll().toString(); } public void add(String item_name, String qty){ repo.add(new Item(item_name, Integer.parseInt(qty))); return; } public void update(String item_name, String qty){ repo.update(new Item(item_name, Integer.parseInt(qty))); return; } public void delete(String item_name, String qty){ repo.remove(new Item(item_name, Integer.parseInt(qty))); return; } } </code></pre> <p>From the HTML page of the PhoneGap app, I am trying to call <code>CouchDBConnector</code> class to get all the documents or a string "No Items found" but I get null pointer exceptions. Here's the stack trace:</p> <pre><code>`12-14 16:12:45.273: I/dalvikvm(675): java.lang.NullPointerException: 12-14 16:12:45.273: I/dalvikvm(675): at com.phonegap.TestDB.CouchDBConnector.getAllItems(CouchDBConnector.java:44) 12-14 16:12:45.273: I/dalvikvm(675): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method) 12-14 16:12:45.273: I/dalvikvm(675): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method) 12-14 16:12:45.273: I/dalvikvm(675): at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:115) 12-14 16:12:45.273: I/dalvikvm(675): at android.os.Handler.dispatchMessage(Handler.java:99) 12-14 16:12:45.273: I/dalvikvm(675): at android.os.Looper.loop(Looper.java:137) 12-14 16:12:45.273: I/dalvikvm(675): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:722) 12-14 16:12:45.283: I/dalvikvm(675): at java.lang.Thread.run(Thread.java:856) 12-14 16:12:45.293: I/dalvikvm(675): "WebViewCoreThread" prio=5 tid=11 NATIVE 12-14 16:12:45.303: I/dalvikvm(675): | group="main" sCount=0 dsCount=0 obj=0x41381ca0 self=0x1dbf90 12-14 16:12:45.303: I/dalvikvm(675): | sysTid=688 nice=0 sched=0/0 cgrp=default handle=1748120 12-14 16:12:45.312: I/dalvikvm(675): | schedstat=( 3460347960 1824920390 1206 ) utm=321 stm=24 core=0 12-14 16:12:45.312: I/dalvikvm(675): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method) 12-14 16:12:45.312: I/dalvikvm(675): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method) 12-14 16:12:45.323: I/dalvikvm(675): at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:115) 12-14 16:12:45.323: I/dalvikvm(675): at android.os.Handler.dispatchMessage(Handler.java:99) 12-14 16:12:45.323: I/dalvikvm(675): at android.os.Looper.loop(Looper.java:137) 12-14 16:12:45.333: I/dalvikvm(675): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:722) 12-14 16:12:45.343: I/dalvikvm(675): at java.lang.Thread.run(Thread.java:856) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload