1

I am trying to use proteus to get dynamic views using json in a simple android app.but I am getting null pointer exception. `

 JsonReader readerlayout = new JsonReader(new StringReader("layouts.json"));

 readerlayout.setLenient(true);

  JsonReader readerdata = new JsonReader(new StringReader("user.json"));

 readerdata.setLenient(true);

try {

layout = proteusTypeAdapterFactory.LAYOUT_TYPE_ADAPTER.read(readerlayout);

data = proteusTypeAdapterFactory.OBJECT_TYPE_ADAPTER.read(readerdata);

} 
catch (IOException e) 
{
   throw new RuntimeException(e);
}

view = layoutInflater.inflate(layout, data, container, 0);
container.addView(view.getAsView());`

despite having json files for layout and data in assets folder,i am getting this error.

java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.flipkart.android.proteus.value.Layout.type' on a null object reference

THanks in advance.

  • I can help but probably tomorrow, travelling right now. Try to reverse engineer [proteus-demo](https://github.com/adityasharat/proteus-demo). Also if possible please share the layout and data JSON. Remember to register or use the Proteus Type Adapter Factory with Gson. – vader Jul 01 '19 at 13:37

1 Answers1

0

Might I suggest checking out simple-proteus-demo.

Primarily you need to do the following things to get proteus working correctly:

  1. create a new instance of proteus.
  2. register proteus with a ProteusTypeAdapterFactory to deserialize proteus JSONs
  3. deserialize layout and data using ProteusTypeAdapterFactory
  4. create a new Proteus Context and get a ProteusLayoutInflater
  5. inflate the layout
  6. get the Android View from the ProteusView and use it as usual
vader
  • 889
  • 8
  • 22