This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Display colors from an array list in second activity's background = app crash (log provided)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new at this and any help is appreciated! -=)

I have colors in an array list that are chosen in the **settings** activity using checkboxes. I want these to be displayed in the **sequence** activity's background in a loop.

The colors are from the "colors.xml" values. Currently the app keeps crashing when going from the *settings* activity to the *sequence* activity.

Settings Activity:


Sequence Activity:


Colors.xml (example of colors – had to remove most to be able to submit post -=)



Logcat:
   
 
Marshal
Posts: 68115
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

That appears to be an Android question, so I am moving you to our Android forum.
 
Rancher
Posts: 453
7
Android Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is on this line
You are using getResources().getColor() wrongly.

From docs::

the parameter of getColor should be a single color value in the form 0xAARRGGBB.


So, the correct way should be or you can simply fix it using
 
Bob Parker
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks - That worked to get rid of that pesky error message. -=)

I'm trying to pass the color array "colorList" from the "Settings" activity over to the "Sequence" activity so that individual colors can be later displayed and animated on the activity's background. I've tried the following which did not appear to pass the colors:



I have also tried the following which gave me gave me a crash (code string is followed by error).




Error:
E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.example.lightbox, PID: 26746
   java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
       at java.util.ArrayList.get(ArrayList.java:437)
       at com.example.lightbox.SettingsActivity$1.onClick(SettingsActivity.java:154)
       at android.view.View.performClick(View.java:7125)
       at android.view.View.performClickInternal(View.java:7102)
       at android.view.View.access$3500(View.java:801)
       at android.view.View$PerformClick.run(View.java:27336)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Any Ideas?
 
Rancher
Posts: 4493
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You declare colorInts on line 6, and there is nothing populating it with anything before you attempt to get data out of it in line 8.

What is that code actually supposed to be doing?
 
Bob Parker
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I understood from a post on another site:

https://stackoverflow.com/questions/44693302/why-arraylist-cannot-store-color-in-processing

the color values in colorList are not being stored as needed and the items in it had to be "listed" in another array and parsed as shown
 
Dave Tolls
Rancher
Posts: 4493
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So are you supposed to add all the colors in colorList into your colorInts List?
In which case you need ot do that.  At the moment you are just trying to get something from colorInts that doesn't exist, because colorInts is empty.

 
Bob Parker
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see what you mean, but isn't it possible to use the original colorList arrayList as in the following code:

       sequence_go.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Intent intent = new Intent(getApplicationContext(), Sequence_Activity.class);
               intent.putExtra("seqColors", colorList);
               System.out.println("Colors in colorList are: " + colorList);
               Toast.makeText(SettingsActivity.this, "To Sequence_Activity", Toast.LENGTH_SHORT).show();
               startActivity(intent);
           }
       });

The app runs and the system prints the integers related to the colors in the array that were selected (it found them in colorList):

I/System.out: Colors in colorList are: [2131034138, 2131034190, 2131034202, 2131034175]

yet they do not appear in the background of the following activity?
 
Bob Parker
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For reference, the following is the code from the Sequence activity:

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_sequence);
       ConstraintLayout sequence = findViewById(R.id.sequence_screen);

       Bundle bundle = getIntent().getExtras();
       int bgColor = bundle.getInt("seqColors", -1);
       sequence.setBackgroundColor(bgColor);

Is this the correct way to "receive" the colors from the previous activity? Thanks again
 
Bob Parker
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is found under "Run"

I/System.out: Colors in colorList are: [2131034201, 2131034218, 2131034144]
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@e92f58b
W/Bundle: Key seqColors expected Integer but value was a java.util.ArrayList.  The default value -1 was returned.
W/Bundle: Attempt to cast generated internal exception:
   java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Integer
       at android.os.BaseBundle.getInt(BaseBundle.java:1041)
       at com.example.lightbox.Sequence_Activity.onCreate(Sequence_Activity.java:23)
       at android.app.Activity.performCreate(Activity.java:7802)
       at android.app.Activity.performCreate(Activity.java:7791)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)
I/chatty: uid=10133(com.example.lightbox) RenderThread identical 19 lines
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@6c14e9d
D/android.widget.GridLayout: horizontal constraints: x1-x0>=161, x2-x1>=1080, x2-x0<=1080 are inconsistent; permanently removing: x2-x0<=1080.
D/EGL_emulation: eglMakeCurrent: 0xe537b000: ver 3 1 (tinfo 0xefdc0260)


How do I convert the colors in the arrayList to integers that can be used in this sequence?
 
What's that smell? I think this tiny ad may have stepped in something.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!