I am struggling with creating object this method - methods

This method is not working
/**
* Outputs all details of all customers to the terminal window.
*/
public void getAllBorrowers()
{
int index = 0;
while(index < borrowers.size())
{
borrowers.get(index);
index++;
}
System.out.println("Number of borrowers: " + getNumberOfBorrowers());
}

I am not very sure what are you trying to do here.
But from the function it looks like you are getting borrower from
borrowers.get(index);
But not getting the value and printing it.
Can you please let know what exactly you are expecting here?

Related

xamarin android: showing ads in recycleview hide some articles in rss entries

I'm trying to show ads in recycleview and i succeeded to do it using the code below .. the problem is that in every "MspaceBetweenAds" position the ad show up but the article at this replaced with the ad
i tried to fix it by modifying ItemCount() by Mposts.Count + (Mposts.count% MspaceBetweenAds) but i'm getting "IndexOutOfBounds " error
any help please .. this is my code
public class AdsView : ListViewHolder
{
public AdView mAdView { get; private set; }
public AdsView(View view) : base(view)
{
mAdView = view.FindViewById<AdView>(Resource.Id.AdsCard);
}
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
RecyclerView.ViewHolder vh = null;
switch (viewType)
{
case 1:
View vBig = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.BigCard, parent, false);
vh = new MyView(vBig);
break;
case 2:
View vAds = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.AdsCard, parent, false);
vh = new AdsView(vAds);
break;
}
return vh;
}
public override void OnBindListViewHolder(ListViewHolder holder, int position)
{
var MyHolder = holder as MyView;
switch (holder.ItemViewType)
{
case 1:
// code to show posts articles here
break;
case 2:
var AdHolder = holder as AdsView;
fnc.AddBannerAd(AdHolder.mAdView);
break;
}
}
public override int GetItemViewType(int position)
{
if (position > 0 && position % mSpaceBetweenAds == 0) { return 2; }
else { return 1; }
}
and this is a demo app https://drive.google.com/open?id=1Tk3G8dw9nqIffxmEFNGqIgXNzCJJPxD_
As the demo you posted contains 3rd party package, I cannot run it directly and modify the demo for you. The flowing is my solution to your problem:
Error causes:
The way you do (modifying ItemCount() by Mposts.Count + (Mposts.count% MspaceBetweenAds) cannot change the real length of Mposts, as a result, it results in the
"IndexOutOfBounds " error.
Solution
If you want to insert ads into your recylerview, you need not only modify your adapter to show both item and ads, but also need to modify your layout resource file, that is, you need to insert the ads data into the data list for of your recylerview. Or you can simply add a duplicated item to the list every [MspaceBetweenAds]items.

Tree View not getting displayed

I was trying to create a treeview browser for my application but got stuck somewhere.
The treeview isn't getting displayed.
Code:
System::IO::DirectoryInfo^ info = gcnew System::IO::DirectoryInfo(path);
System::IO::Directory^ dir;
if (dir->Exists(path))
{
try
{
array<System::IO::DirectoryInfo^>^ dirs = info->GetDirectories();
if (dirs->Length > 0)
{
for (int i = 0; i < dirs->Length; i++)
{
TreeNode^ node = treeView1->Nodes[0]->Nodes->Add(dirs[i]->Name);
node->ImageIndex = 1;
for (int j = 0; j < dirs[i]->GetFiles()->Length; j++)
{
if (dirs[i]->GetFiles()[j]->Exists)
{
TreeNode^ nodes = treeView1->Nodes[0]->Nodes[node->Index]->Nodes->Add(dirs[i]->GetFiles()[j]->Name);
nodes->ImageIndex = 2;
}
}
}
}
}
catch (Exception^ e)
{
MessageBox::Show(e->Message);
}
}
Did you use splitcontainer and fill in the first section with your data first?
How did you initialize the new treeview class?
Example:
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[DockingAttribute(DockingBehavior::Ask)]
public ref class TreeView : public Control
Then you can implement treeview and imageview.
For example, ShGetFolderLocation is one way to pull file locations, for windows OS.
Remember you have to populate the view and tell the system to display it for you to see it.
Or just go to: this earlier solution for the same issue
Follow up with the code for nodemouse click or whatever input response you are looking for such as expand or close, go to link and so on.

clearTextField() is not working in UIAutomator

i am new bee to uiautomator and when i am trying to clear the text field text with clearTextField() its not at all clearing. Can some one guide me how can i do this.
tried in this way also
while(!"".equals(obj.getText())
obj.clearTextField();
Thanks in advance.
For security reasons, we can't get the text from a password edittext. Unfortunally clearTextField() does not work on API 18 so:
obj.getText() = ""
obj.getText().lenght() = 0
My solution, not very beautifull i know, is:
private static void clearText(UiDevice uiDevice, UiObject textBox) throws UiObjectNotFoundException {
int estimatedLength = 30;
textBox.clickBottomRight();
for (int i = 0; i < estimatedLength; i++) {
uiDevice.pressDelete();
}
}
You can try following code :
String text = obj.getText();
obj.clickBottomRight();
for (int i=0;i<text.length();i++) {
UiDevice.getInstance().pressDelete();
}
obj.setText("some-text");

NullPointerException while returning a JLabel

i seem to have a nullPointerException without any reason, could you please review piece of my code and tell me your opinion?
This is the class and the constructor that i am calling on another class in order to get a label randomly (using the shuffle, which is randomizing as well) from a linked list.
here is the
public class RandomHeuristic {
GameInterface game;
JLabel randomLabel;
public JLabel RandomHeuristic() {
randomLabel = (JLabel) game.labels.getFirst();
int counter = 0;
do {
Collections.shuffle(game.labels);
randomLabel = (JLabel) game.labels.getFirst();
counter++;
if (counter == 100) {
break;
}
/*
* Debugging
* System.out.println(randomLabel.getText());
*/
} while (randomLabel != null && game.isLegalMove(randomLabel) == false);
//Retrieves and removes the head (first element) of this list.
if(randomLabel == null){
RandomHeuristic();
}
//game.labels.remove(randomLabel);
return randomLabel;
}
}
And here is where i am calling the constructor, the playHeuristicMove() is expecting a JLabel i checked it on debugging that is working correctly, though i still get a nullPointer Exception when i call it. randomHeuristicOne is created on the same class like this: RandomHeuristic randomHeuristicOne;
playHeuristicMove(randomHeuristicOne.RandomHeuristic());
Perhaps you want to take a look at your game GameInterface object it seems it's never been instantiated

Comparison method violates its general contract! Java 7 only

I know this has been an issue for a while now, and checked all previously answers I could get, but still this one doesn't work.
The object 'crew' represents crewmembers with ranks and other items. The comparison should be made by comparing 'assigned_rank', an int value, and if this value is equal in both instances, then 'is_trainer', a boolean, should make the difference.
This method worked great as long as it was running with java < 7. But since Java 7 I keep getting this one:
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.ComparableTimSort.mergeLo(ComparableTimSort.java:714)
at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:451)
at java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:376)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:182)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
at java.util.Arrays.sort(Arrays.java:472)
at java.util.Collections.sort(Collections.java:155)
at dormas_flightlog.Query.getCrew(Query.java:714)
Here is the source, where some potentially dangerous parts have allready been out-commented, but it still does not work:
public class crew implements Serializable, Comparable<crew> {
private static final long serialVersionUID = 36L;
private int flightID = 0;
private int assigned_rank = 25;
private boolean is_trainer = false;
...
#Override
public int compareTo(crew him) {
int myRank = this.getAssigned_rank();
int hisRank = him.assigned_rank;
if (this == him) {
return 0;
}
if (myRank > hisRank) {
return 1;
}
if (myRank < hisRank) {
return -1;
}
if (myRank == hisRank) {
// if (is_trainer && !o.is_trainer) {
// i = 1;
// }
// if (!is_trainer && o.is_trainer) {
// i = -1;
// }
// if (is_trainer && o.is_trainer) {
// i = 0;
// }
// if (!is_trainer && !o.is_trainer) {
// i = 0;
// }
return 0;
}
return 0;
}
#Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + this.assigned_rank;
hash = 31 * hash + (this.is_trainer ? 1 : 0);
return hash;
}
#Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
int myRank = this.getAssigned_rank();
int hisRank = 0;
if (o instanceof crew) {
crew him = (crew) o;
hisRank = him.assigned_rank;
} else {
return false;
}
if (myRank > hisRank) {
return false;
}
if (myRank < hisRank) {
return false;
}
if (myRank == hisRank) {
// if (is_trainer && !o.is_trainer) {
// i = 1;
// }
// if (!is_trainer && o.is_trainer) {
// i = -1;
// }
// if (is_trainer && o.is_trainer) {
// i = 0;
// }
// if (!is_trainer && !o.is_trainer) {
// i = 0;
// }
return true;
}
return false;
}
}
Implementing equals() was just a try to solve this problem. The given exception comes with or without equals(). I cannot see how the compareTo-method violates its contract. Any help is greatly appreciated....one day this code has to work with java 7 and I don't know how...
Thanks
see this:
From http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#source
Area: API: Utilities Synopsis: Updated sort behavior for Arrays and
Collections may throw an IllegalArgumentException
Description: The sorting algorithm used by java.util.Arrays.sort and
(indirectly) by java.util.Collections.sort has been replaced. The new
sort implementation may throw an IllegalArgumentException if it detects
a Comparable that violates the Comparable contract. The previous
implementation silently ignored such a situation. If the previous
behavior is desired, you can use the new system
property java.util.Arrays.useLegacyMergeSort, to restore previous
mergesort behavior.
Nature of Incompatibility: behavioral
RFE: 6804124
For more detailed info, see the bug database reference here.
maybe you just have NaN values which you compare through Collections.sort(...), this has been a problem to me and I got that exception even having right implementation of compare(obj1, obj2) method! Check that!
I was able to solve this error cause it was a bug in jdk7.
here I found the solution:
"Comparison method violates its general contract!" - TimSort and GridLayout
Basically i just had to add the
JAVA_OPTS="$JAVA_OPTS -Djava.util.Arrays.useLegacyMergeSort=true"
to my jboss
Unfortunately, none of the solutions work for Android. TimSort is used deep in Android's ViewGroup relating to addChildrenForAccessibility that shows up under Java 7 & 8. No user code is involved in any comparison.
From other reports, it is related to having RelativeLayout with overlapping items as is commonly done. For example, a TextView that appears over an Image, or two items at the same location, where you only set one visible at a time.
https://code.google.com/p/android/issues/detail?id=55933
I've not found any way around the bug. You can't set a -Djava option in Android Studio or Eclipse (at least that I could find). Forcing use of Java 1.6 should work, but doesn't. Seems like Amazon's newer Fire tablets and phones are far more sensitive to this bug than other devices.
There are rumors Java 9 will have a fix such as a run-time option that works, but with a bug that's been around for years, I have doubts it will ever be fixed - especially considering the animosity between Oracle and Google. Any yes, perhaps the bug is really deep in the Android code and should be fixed there. With more than a billion devices out there, that's not a viable solution for all the existing devices.

Resources