Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6967847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:22:32+00:00 2026-05-27T16:22:32+00:00

I have simple item model with name and quantity: public class Item extends CouchDbDocument{

  • 0

I have simple item model with name and quantity:

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;
}
}

and an Item Repository class

public class ItemRepository extends CouchDbRepositorySupport<Item>{

public ItemRepository(CouchDbConnector db) {
        super(Item.class, db);
        initStandardDesignDocument();
}
@GenerateView @Override
public List<Item> getAll() {
    ViewQuery q = createQuery("all").descending(true);
    return db.queryView(q, Item.class);
}

and an Item Controller

public class ItemController {
ItemRepository itemRepository;

public String viewAll() {
    List<Item> items = itemRepository.getAll();        
    return items.toString();
}
}

I have a CouchDBConnector class which is added as javascript interface:

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;
}
}

From the HTML page of the PhoneGap app, I am trying to call CouchDBConnector class to get all the documents or a string “No Items found” but I get null pointer exceptions. Here’s the stack trace:

`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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:22:32+00:00Added an answer on May 27, 2026 at 4:22 pm

    Looks like you forgot to call init() from your constructor, because the NPE is in getAllItems(), so eiter repo is null or repo.getAll() is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple class that includes a GenericRelation class Item(models.Model): name = models.CharField
Hopefully this is simple: I have a relatively long list where each list item
I have a model that looks like this: class Category(models.Model): name = models.CharField(max_length=60) class
Very simple example: Model: require 'inventory' class CustomerOrder < ActiveRecord::Base validates_presence_of :name validate :must_have_at_least_one_item,
I have a simple demo app like this Friend = Backbone.Model.extend name:null Friends =
I have a very simple cart which displays the item quantity in a text_field,
I have a model class like this: namespace Models { public struct Localization {
I have a model that looks something like this: public class SampleModel { public
I've got a basic Item model in my Django app: class Item(models.Model): name =
I have a simple unordered list with list items as menu item i created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.