I am trying to create a scrollable view where the cards are taken from different activities. I have an activity with a card something like this:
public class SampleA extends Activity {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getCard();
}
public Card getCard()
{
Card carda = new Card(this); //ERROR HERE
carda.setText("card1");
View cardView = carda.getView();
setContentView(cardView);
return carda;
}
}
And another card which is similar to the above one. Now I am calling the method getCard
for both the cards inside another activity which will be my scroll.
public class SampleB extends Activity {
private static ArrayList<Card> sourceCard = new ArrayList<Card>();
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
sampleaa ss = new sampleaa();
Card card1 = ss.getCard();
sourceCard.add(card1);
samplec ss1 = new samplec();
Card card2 = ss1.getCard();
sourceCard.add(card2);
CardScrollView csvCardsView = new CardScrollView(this);
csaAdapter cvAdapter = new csaAdapter();
csvCardsView.setAdapter(cvAdapter);
csvCardsView.activate();
setContentView(csvCardsView);
}
private static class csaAdapter extends CardScrollAdapter {
//adapter code
}
}
I am getting a NullPointerException
in the above code.
Update Pasting the logcat error here:
05-15 17:04:46.646: I/System.out(4832): com.google.android.glass.app.Card@20d7b544
05-15 17:04:46.771: D/OpenGLRenderer(4832): Enabling debug mode 0
05-15 17:04:46.826: V/RenderScript(4832): 0x5a36a5b8 Launching thread(s), CPUs 2
05-15 17:04:46.826: D/RenderScript(4832): Load RS driver 'libRSDriver.so' successfully.
05-15 17:04:47.873: I/System.out(4832): TAP
05-15 17:04:47.873: I/System.out(4832): in TAP
05-15 17:04:47.896: D/AndroidRuntime(4832): Shutting down VM
05-15 17:04:47.896: W/dalvikvm(4832): threadid=1: thread exiting with uncaught exception (group=0x415e3bd8)
05-15 17:04:47.896: E/AndroidRuntime(4832): FATAL EXCEPTION: main
05-15 17:04:47.896: E/AndroidRuntime(4832): Process: com.example.sampleapp, PID: 4832
05-15 17:04:47.896: E/AndroidRuntime(4832): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sampleapp/com.example.sampleapp.Sampleb}: java.lang.NullPointerException
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2235)
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2285)
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.app.ActivityThread.access$800(ActivityThread.java:138)
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.os.Handler.dispatchMessage(Handler.java:102)
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.os.Looper.loop(Looper.java:149)
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.app.ActivityThread.main(ActivityThread.java:5061)
05-15 17:04:47.896: E/AndroidRuntime(4832): at java.lang.reflect.Method.invokeNative(Native Method)
05-15 17:04:47.896: E/AndroidRuntime(4832): at java.lang.reflect.Method.invoke(Method.java:515)
05-15 17:04:47.896: E/AndroidRuntime(4832): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
05-15 17:04:47.896: E/AndroidRuntime(4832): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
05-15 17:04:47.896: E/AndroidRuntime(4832): at dalvik.system.NativeStart.main(Native Method)
05-15 17:04:47.896: E/AndroidRuntime(4832): Caused by: java.lang.NullPointerException
05-15 17:04:47.896: E/AndroidRuntime(4832): at com.google.android.glass.app.Card.<init>(Card.java:98)
05-15 17:04:47.896: E/AndroidRuntime(4832): at com.example.sampleapp.Sampleaa.getCard(Sampleaa.java:26)
05-15 17:04:47.896: E/AndroidRuntime(4832): at com.example.sampleapp.Sampleb.onCreate(Sampleb.java:25)
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.app.Activity.performCreate(Activity.java:5236)
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1089)
05-15 17:04:47.896: E/AndroidRuntime(4832): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
05-15 17:04:47.896: E/AndroidRuntime(4832): ... 11 more
05-15 17:04:47.912: I/Process(4832): Sending signal. PID: 4832 SIG: 9