Having issue while recursively parsing xml using Stax and xslt

While reading the xml file recursively using Stax and xslt, I am only getting 1st iteration data. It is not moving to the next ones.

Here is my sample xml data:

<Root node>
 <ParentNode>
   <ChildNode1 a1, a2, a3,a4 ...>
      <SubChild1 b1, b2, b3, b4 ../>
      <SubChild2 c1, c2, c3, c4 ../>
      <SubChild3 d1, d2, d3, d4 ..>
            <GrandChild1  e1, e2, e3, e4 ../>
            <GrandChild2  f1, f2, f3, f4 ../>
            <GrandChild3  g1, g2, g3, g4 ../>
      </SubChild3>
   <ChildNode1>
   <ChildNode2 h1, h2, h3 ...>
      <SubChild4 i1, i2, i3 ...>
          <GrandChild4 j1, j2, j3 .../>
          <GrandChild5 k1, k2, k3 .../>
      </SubChild4>
      <SubChild5>
         <GrandChild6>
            <GreatGrandChild1 l1, l2, l3 ../>
         </GrandChild6>
      </SubChild5>
   </ChildNode2>
   <ChildNode2 h1, h2, h3 ...>
      <SubChild4 i1, i2, i3 ...>
          <GrandChild4 j1, j2, j3 .../>
          <GrandChild5 k1, k2, k3 .../>
      </SubChild4>
      <SubChild5>
         <GrandChild6>
            <GreatGrandChild1 l1, l2, l3 ../>
         </GrandChild6>
      </SubChild5>
   </ChildNode2>
   <ChildNode2 h1, h2, h3 ...>
      <SubChild4 i1, i2, i3 ...>
          <GrandChild4 j1, j2, j3 .../>
          <GrandChild5 k1, k2, k3 .../>
      </SubChild4>
      <SubChild5>
         <GrandChild6>
            <GreatGrandChild1 l1, l2, l3 ../>
         </GrandChild6>
      </SubChild5>
   </ChildNode2>
   .
   .
   .
   <ChildNode2>
   . . . .
   </ChildNode2>
   ------ This is 1 iteration from ChildNode1 to Chn ------
   <ChildNode1 a1, a2, a3,a4 ...>
      <SubChild1 b1, b2, b3, b4 ../>
      <SubChild2 c1, c2, c3, c4 ../>
      <SubChild3 d1, d2, d3, d4 ..>
            <GrandChild1  e1, e2, e3, e4 ../>
            <GrandChild2  f1, f2, f3, f4 ../>
            <GrandChild3  g1, g2, g3, g4 ../>
      </SubChild3>
   <ChildNode1>
   <ChildNode2 h1, h2, h3 ...>
      <SubChild4 i1, i2, i3 ...>
          <GrandChild4 j1, j2, j3 .../>
          <GrandChild5 k1, k2, k3 .../>
      </SubChild4>
      <SubChild5>
         <GrandChild6>
            <GreatGrandChild1 l1, l2, l3 ../>
         </GrandChild6>
      </SubChild5>
   </ChildNode2>
   <ChildNode2 h1, h2, h3 ...>
      <SubChild4 i1, i2, i3 ...>
          <GrandChild4 j1, j2, j3 .../>
          <GrandChild5 k1, k2, k3 .../>
      </SubChild4>
      <SubChild5>
         <GrandChild6>
            <GreatGrandChild1 l1, l2, l3 ../>
         </GrandChild6>
      </SubChild5>
   </ChildNode2>
   <ChildNode2 h1, h2, h3 ...>
      <SubChild4 i1, i2, i3 ...>
          <GrandChild4 j1, j2, j3 .../>
          <GrandChild5 k1, k2, k3 .../>
      </SubChild4>
      <SubChild5>
         <GrandChild6>
            <GreatGrandChild1 l1, l2, l3 ../>
         </GrandChild6>
      </SubChild5>
   </ChildNode2>
   .
   .
   .
    <ChildNode2>
   . . . .
   </ChildNode2>
   ------ This is 2 iteration from ChildNode1 to Chn ------
   <ChildNode1 a1, a2, a3,a4 ...>
      <SubChild1 b1, b2, b3, b4 ../>
      <SubChild2 c1, c2, c3, c4 ../>
      <SubChild3 d1, d2, d3, d4 ..>
            <GrandChild1  e1, e2, e3, e4 ../>
            <GrandChild2  f1, f2, f3, f4 ../>
            <GrandChild3  g1, g2, g3, g4 ../>
      </SubChild3>
   <ChildNode1>
    <ChildNode2 h1, h2, h3 ...>
      <SubChild4 i1, i2, i3 ...>
          <GrandChild4 j1, j2, j3 .../>
          <GrandChild5 k1, k2, k3 .../>
      </SubChild4>
      <SubChild5>
         <GrandChild6>
            <GreatGrandChild1 l1, l2, l3 ../>
         </GrandChild6>
      </SubChild5>
   </ChildNode2>
   <ChildNode2 h1, h2, h3 ...>
      <SubChild4 i1, i2, i3 ...>
          <GrandChild4 j1, j2, j3 .../>
          <GrandChild5 k1, k2, k3 .../>
      </SubChild4>
      <SubChild5>
         <GrandChild6>
            <GreatGrandChild1 l1, l2, l3 ../>
         </GrandChild6>
      </SubChild5>
   </ChildNode2>
   <ChildNode2 h1, h2, h3 ...>
      <SubChild4 i1, i2, i3 ...>
          <GrandChild4 j1, j2, j3 .../>
          <GrandChild5 k1, k2, k3 .../>
      </SubChild4>
      <SubChild5>
         <GrandChild6>
            <GreatGrandChild1 l1, l2, l3 ../>
         </GrandChild6>
      </SubChild5>
   </ChildNode2>
   .
   .
   .
    <ChildNode2>
   . . . .
   </ChildNode2>
   ------like this we have n number of Iterations------
 </ParentNode>
</Root node>      

This is my sample xslt file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                          xmlns:x="http://www.fixprotocol.org/FIXML-5-0-SP2" 
                          xsi:schemaLocation="http://www.fixprotocol.org/FIXML-5-0-SP2 fixml-main-5-0-SP2_.xsd"
                          xmlns:math="http://www.w3.org/2005/xpath-functions/math"
                          exclude-result-prefixes="xs math">

  <xsl:mode streamable="yes"/>
  <xsl:output method="text" encoding="utf-8" />

  <xsl:param name="delim" select="'|'" />
  <xsl:param name="break" select="'&#xA;'" />



  <xsl:template match="/">
   <xsl:text> a1 | a2| d1| d2| e1| e2| f1| f2| h1| h2| h3| j1| j2| k1| k2| l1 </xsl:text>
   <xsl:text>&#xA;</xsl:text> 
   <xsl:apply-templates select="descendant::x:ParentNode"/>

  </xsl:template>


  <xsl:template match="x:ParentNode">

 <xsl:value-of select="concat( normalize-space(x:ChildNode1/@a1))" /><xsl:value-of select="$delim" />
 <xsl:value-of select="concat( normalize-space(x:ChildNode1/@a2))" /><xsl:value-of select="$delim" />

 <xsl:value-of select="concat( normalize-space(x:ChildNode1/x.SubChild3/@d1))" /><xsl:value-of select="$delim" />
 <xsl:value-of select="concat( normalize-space(x:ChildNode1/x.SubChild3/@d2))" /><xsl:value-of select="$delim" />

 <xsl:value-of select="concat( normalize-space(x:ChildNode1/x.SubChild3/x.GrandChild1/@e1))" /><xsl:value-of select="$delim" />
 <xsl:value-of select="concat( normalize-space(x:ChildNode1/x.SubChild3/x.GrandChild1/@e2))" /><xsl:value-of select="$delim" />

 <xsl:value-of select="concat( normalize-space(x:ChildNode1/x.SubChild3/x.GrandChild2/@f1))" /><xsl:value-of select="$delim" />
 <xsl:value-of select="concat( normalize-space(x:ChildNode1/x.SubChild3/x.GrandChild2/@f2))" /><xsl:value-of select="$delim" />


 <xsl:value-of select="concat( normalize-space(x:ChildNode2/x:SubChild4/@h1))" /><xsl:value-of select="$delim" />
 <xsl:value-of select="concat( normalize-space(x:ChildNode2/x:SubChild4/@h2))" /><xsl:value-of select="$delim" />
 <xsl:value-of select="concat( normalize-space(x:ChildNode2/x:SubChild4/@h3))" /><xsl:value-of select="$delim" />

 <xsl:value-of select="concat( normalize-space(x:ChildNode2/x:SubChild4/x:GrandChild4/@j1))" /><xsl:value-of select="$delim" />
 <xsl:value-of select="concat( normalize-space(x:ChildNode2/x:SubChild4/x:GrandChild4/@j2))" /><xsl:value-of select="$delim" />

 <xsl:value-of select="concat( normalize-space(x:ChildNode2/x:SubChild4/x:GrandChild5/@k1))" /><xsl:value-of select="$delim" />
 <xsl:value-of select="concat( normalize-space(x:ChildNode2/x:SubChild4/x:GrandChild5/@k2))" /><xsl:value-of select="$delim" />
 <xsl:value-of select="concat( normalize-space(x:ChildNode2/x:SubChild5/x.GrandChild6/x.GreatGrandChild1/@l1))" /><xsl:value-of select="$delim" />

 </xsl:template>
 </xsl:stylesheet>

This is my Java code:

public class Xml2Csv {

public static int transform(InputStream is, OutputStream os, Transformer transformer, QName name) throws XMLStreamException, TransformerException {
    long time1 = System.nanoTime();
    // Open input & output files
    XMLInputFactory factory = XMLInputFactory.newInstance();
    factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
    factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
    XMLStreamReader reader = factory.createXMLStreamReader(is);
    // In case you want to check which implementation is used.
    // Woodstox is a bit faster, but not worth adding extra dependency.
   //        System.out.println("Reader="+reader);
//        System.out.println("Transformer="+transformer);

    Result result = new StreamResult(os);

    int count = 0;
    while (reader.hasNext()) {
        if (reader.getEventType() == XMLStreamReader.START_ELEMENT && name.equals(reader.getName())) {
            // System.out.println("FOUND " + count);
            count++;
            transformer.transform(new StAXSource(reader), result);
            if (count % 1000 == 0) {
                long time2 = System.nanoTime();
                double ms = (time2 - time1) / 1000000.0;
                System.out.format("Time=%.2fms Rows=%d%n", ms, count);
            }
        } else if (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
//                    System.out.println("Start "+reader.getName()+" != "+name);
        }
        reader.next();
    }
    long time2 = System.nanoTime();
    double ms = (time2 - time1) / 1000000.0;
    System.out.format("Total Time=%.2fms Total rows=%d%n", ms, count);
    return count;
}

public static void main(String arg[]) throws Exception {
    // Parse command line options
    File xsltFile;
    File inputFile;
    File outputFile;
    String tagName;
    String namespace;
    try {
        String xsltFileName = parse("-x", arg, "XSLT sheet", true);
        String inputFileName = parse("-f", arg, "Input file", true);
        String outputFileName = parse("-o", arg, "Output file", true);
        tagName = parse("-t", arg, "Tag name", true);
        namespace = parse("-n", arg, "Tag Namespace URL", false);
        xsltFile = new File(xsltFileName);
        inputFile = new File(inputFileName);
        outputFile = new File(outputFileName);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        System.err.println("Syntax: Xml2Csv -f <input file> -o <output file> -x <XSLT stylesheet> -t <Tag name> [-n <namespace URL>]");
        System.err.println("Will split given file on given tag with given namespace.");
        System.err.println("Will process contents of each tag using given XSLT.");
        System.exit(1);
        return;
    }
    if (!xsltFile.exists()) {
        System.err.println("File not found " + xsltFile.getAbsolutePath());
        System.exit(1);
    }
    if (!inputFile.exists()) {
        System.err.println("File not found " + inputFile.getAbsolutePath());
        System.exit(1);
    }

    // Open XSLT stylesheet
    StreamSource stylesource = new StreamSource(xsltFile);
    Transformer transformer = TransformerFactory.newInstance().newTransformer(stylesource);

    // Create XML tag name which is used to break up XML into rows
    final QName name;
    if (namespace != null) {
        name = new QName(namespace, tagName);
    } else {
        name = new QName(tagName);
    }
    System.out.println("Will look for tag " + name + " in namespace " + namespace);

    FileOutputStream fos = null;
    FileInputStream fis = null;
    try {
        // Open input & output files
        fis = new FileInputStream(inputFile);
        fos = new FileOutputStream(outputFile);
        transform(fis, fos, transformer, name);
    } finally {
        if (fos != null) {
            fos.close();
        }
        if (fis != null) {
            fis.close();
        }
    }
}

// Teo - inefficient, but who cares
private static String parse(String option, String[] arg, String desc, boolean required) throws ParseException {
    for (int i = 0; i < arg.length; i++) {
        if (option.equals(arg[i])) {
            if (i + 1 < arg.length) {
                String value = arg[i + 1].trim();
                return value;
            } else {
                throw new ParseException(option + " must be followed by an argument", i);
            }
        }
    }
    if (required) {
        throw new ParseException(desc + " is required", 0);
    } else {
        return null;
    }
}
}

Output: a1 | a2| d1| d2| e1| e2| f1| f2| h1| h2| h3| j1| j2| k1| k2| l1

I should get all the iterations data but instead I am getting only one Iteration data.

Could you guys help me where can I change the code to get all the Iterations data ?

Java Multiple Constructor Setting Issue

So I am having issues with the multiple constructors that I am using. Basically, I have two WaterDrop constructs where I pass in the initial x and y position (second block of code) into the appropriate constructor. The issue is that it doesn’t set int x, y instance variables to the appropriate starting positions. It sets them fine the the first constructor but then when it draws the dots, using the second constructor, it automatically sets them to the (0, 0) position. Is there anyway I could call the first constructor so it sets the x and y position to the appropriate starting location?

public class WaterDrop
{
// instance variables - replace the example below with your own
private int x;
private int y;
private int xVelocity;
private int yVelocity;
private DrawingPanel panel;
private static int DIAMETER = 1;
private int delayStart;
private int bounceLimit;

private static Random rand = new Random();

public WaterDrop(int x, int y){
    this.x = x; //**These assign just fine but I can't get them to get passed**
    this.y = y;  //**into the next WaterDrop constructor**
                 //**i.e. (200, 400)**

}

public WaterDrop(DrawingPanel panel, boolean move)
{
    //initialise instance variables //**In this constructor they are still**
                                    //**initialized to 0**
    this.panel = panel;  //**Since they are initialized at 0, when I draw the**
                         //**waterDrops they appear at the location (0, 0)**

}

    xVelocity = rand.nextInt(3) - 1;
    yVelocity = rand.nextInt(20) + 1 ;
    delayStart = rand.nextInt(100);
    bounceLimit = 0;

}

This is what I’m passing in from the WaterFountain class:

public class WaterFountain{
....

public WaterFountain(DrawingPanel panel, int xLocation, int yLocation)
{
    this.panel = panel;
    this.xLocation = xLocation;
    this.yLocation = yLocation;

    for(int i = 0; i < NUM_WATER_DROPS; i++){
         waterDrop[i] = new WaterDrop(this.xLocation, this.yLocation);
    }
}


....
}

How to get spinner’s selected item’s view

I’m trying to get a reference to the view of the selected item of my spinner (the layout). I’m using a SimpleCursorAdapter with a custom layout. Here is some of the code for my adapter:

adapter = new SimpleCursorAdapter(getActivity(),
            R.layout.task_row, null,
            new String[] { DbHandler.TASK_TITLE, DbHandler.TASK_NOTE},
            new int[] { R.id.title, R.id.note}, 0);
spinner.setAdapter(adapter);

Here is task_row.xml:

<RelativeLayout>

<ImageView
    android:id="@+id/avatar"
    android:src="@mipmap/ic_launcher"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/avatar" />

<TextView
    android:id="@+id/title"
    android:textStyle="bold"
    android:layout_toRightOf="@id/avatar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/note"
    android:layout_toRightOf="@id/avatar"
    android:layout_below="@id/title"
    android:layout_alignParentBottom="true"
    android:gravity="bottom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

The reason I’m trying to get a reference to the RelativeLayout is so that I can access the text attribute of a TextView child for example. I’m aware that there is a method called getItemSelected() that I can use on my Spinner, but this method returns an object and I don’t know what it is.

Attempt to invoke virtual method ‘void android.support.v7.widget.RecyclerView.setLayoutManager’ on a null object reference

I made a recyclerview in a Fragment, with code like this, before I made this, in the usual activity, and I tried to make it in Fragment Activity, but it happened even error

public class GaweanFragment extends BaseFragment {

@BindView(R.id.rv_gawean_fragment)
RecyclerView rv_gawean_fragment;
@BindView(R.id.prbLoading)
ProgressBar prbLoading;
@BindView(R.id.txvUser)
TextView txvUser;
@BindView(R.id.txvDescription)
TextView txvDescription;
@BindView(R.id.btnSubmit)
Button btnSubmit;
@BindView(R.id.lnrNoList)
LinearLayout lnrNoList;

@BindDrawable(R.drawable.ic_obs_on_white_36px)
public Drawable observationOn;
@BindDrawable(R.drawable.ic_obs_off_white_36px)
public Drawable observationOff;
@BindDrawable(R.drawable.ic_sc_on_white_36px)
public Drawable storecountOn;
@BindDrawable(R.drawable.ic_sc_off_white_36px)
public Drawable storecountOff;

@BindString(R.string.error_no_internet)
public String errorInternet;
@BindString(R.string.request_failed)
public String requestFailed;
@BindString(R.string.error_location_not_found)
public String errorLocationNotFound;
@BindString(R.string.please_wait)
public String pleaseWait;
@BindColor(R.color.colorPrimary)
public int colorPrimary;
@BindColor(R.color.grey_600)
public int colorGrey;

@BindString(R.string.no_order_list_please_order)
public String errorNoList;

private LatLng myLocation;
private Boolean isObservation = true;
private Boolean isStoreCount = false;
private Boolean isMapReady = false;

private GaweanPresenter presenter;
private List<Job> gaweanJobs;
private Job selectedJob;
private android.location.Location locA;
private Float radiusKilometer;

@Override
protected int getLayout() {
    return R.layout.f_gawean;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    initRV();

    presenter = new GaweanPresenter(this);
    gaweanJobs = new ArrayList<>();

    if (ThemeUtil.getThemes() == ThemeUtil.THEME_OBSERVATION) {
        loadObservation();
    } else {
        loadStoreCount();
    }

}


@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

}

@Override
public void onResume() {
    super.onResume();
    gaweanJobs = new ArrayList<>();
    if (ThemeUtil.getThemes() == ThemeUtil.THEME_OBSERVATION) {
        loadObservation();
    } else {
        loadStoreCount();
    }
}

@Override
public void busHandler(RxBusObject.RxBusKey busKey, Object busObject) {
    switch (busKey) {
        case MAP_READY:
            myLocation = (LatLng) busObject;
            if (myLocation != null) {

                isMapReady = true;

                if (isObservation) {
                    presenter.getAssignList(GaweanPresenter.OBSERVATION, Double.toString(myLocation.latitude), Double.toString(myLocation.longitude));
                    presenter.getApplyList(GaweanPresenter.OBSERVATION, Double.toString(myLocation.latitude), Double.toString(myLocation.longitude));
                }

                if (isStoreCount) {
                    presenter.getAssignList(GaweanPresenter.STORE_COUNT, Double.toString(myLocation.latitude), Double.toString(myLocation.longitude));
                    presenter.getApplyList(GaweanPresenter.STORE_COUNT, Double.toString(myLocation.latitude), Double.toString(myLocation.longitude));
                }
            }
            break;

        case SELECT_PLACE:
            Place place = (Place) busObject;

            for (int i = 0; i < gaweanJobs.size(); i++) {
                if (place.getId().equals(gaweanJobs.get(i).getIdJob())) {
                    selectedJob = gaweanJobs.get(i);
                    break;
                }
            }

            showCheckInDialog();

            break;

        case LOCATION_CHANGE:
            myLocation = (LatLng) busObject;
            if (myLocation != null) {
                if (gaweanJobs.size() > 0)
                    loadList();
            }
            break;
    }
}

public void initRV() {
    final LinearLayoutManager llManager = new LinearLayoutManager(getContext());
    llManager.setOrientation(LinearLayoutManager.VERTICAL);
    rv_gawean_fragment.setLayoutManager(llManager);
}

public void loadList(List<Job> jobList) {
    gaweanJobs.addAll(jobList);

    Collections.sort(gaweanJobs, new Comparator<Job>() {
        @Override
        public int compare(Job lhs, Job rhs) {
            // -1 - less than, 1 - greater than, 0 - equal, all inversed for descending

            Double leftDistance = 0d;
            Double rightDistance = 0d;
            if (lhs.getStoreDist() != null) {
                try {
                    leftDistance = Double.parseDouble(lhs.getStoreDist());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (lhs.getAreaDist() != null) {
                try {
                    leftDistance = Double.parseDouble(lhs.getAreaDist());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (rhs.getStoreDist() != null) {
                try {
                    rightDistance = Double.parseDouble(rhs.getStoreDist());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (rhs.getAreaDist() != null) {
                try {
                    rightDistance = Double.parseDouble(rhs.getAreaDist());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            return rightDistance > leftDistance ? -1 : (rightDistance < leftDistance) ? 1 : 0;
        }
    });

    rv_gawean_fragment.setVisibility(View.VISIBLE);
    lnrNoList.setVisibility(View.GONE);
    prbLoading.setVisibility(View.GONE);
    JobListAdapter jobListAdapter = new JobListAdapter(getContext(), gaweanJobs, myLocation);
    rv_gawean_fragment.setAdapter(jobListAdapter);
    rv_gawean_fragment.setNestedScrollingEnabled(true);

    if (gaweanJobs.size() > 0) {

    }
}

public void loadList() {
    rv_gawean_fragment.setVisibility(View.VISIBLE);
    lnrNoList.setVisibility(View.GONE);
    prbLoading.setVisibility(View.GONE);
    rv_gawean_fragment.setAdapter(new JobListAdapter(getContext(), gaweanJobs, myLocation));
    rv_gawean_fragment.setNestedScrollingEnabled(true);
}

public void showNoList(String message, String action) {
    if (gaweanJobs.size() == 0) {
        rv_gawean_fragment.setVisibility(View.GONE);
        lnrNoList.setVisibility(View.VISIBLE);
        prbLoading.setVisibility(View.GONE);
        if (!message.equals(""))
            txvDescription.setText(message);
        btnSubmit.setText(action);
    }
}

private void showCheckInDialog() {
    NumberFormat formatter = new DecimalFormat("#0.00");

    locA = new android.location.Location("");
    locA.setLatitude(myLocation.latitude);
    locA.setLongitude(myLocation.longitude);

    radiusKilometer = Float.parseFloat(selectedJob.getRadiusMeter()) / 1000;

    String name = "";
    String date = "Deadline: " + DateUtil.format(DateUtil.format(selectedJob.getDueDate(), "yyyy-MM-dd"), "EEE, dd-MMM-yyyy");

    String description = selectedJob.getDescription();

    if (selectedJob.getName() != null && !selectedJob.getName().equals("")) {
        name = selectedJob.getStoreName() + "n";
    } else {
        name = selectedJob.getAreaName() + "n";
    }

    String title = "";
    switch (selectedJob.getIdJobType()) {
        case "2":
            title = "Barcode Scan";
            break;
        case "3":
            title = "Area Survey";
            break;
        default:
            title = "Observasi";
    }

    new MaterialDialog.Builder(getContext())
            .backgroundColor(Color.WHITE)
            .title(title)
            .titleColor(colorPrimary)
            .content(name + description + "nn" + date + "nn" + "Ingin memulai job ini?")
            .contentColor(getResources().getColor(R.color.grey_600))
            .positiveText("Ya")
            .positiveColor(colorPrimary)
            .negativeText("Tidak")
            .negativeColor(getResources().getColor(R.color.grey_600))
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    if (selectedJob.isApporved()) {
                        //STORE COUNT
                        if (selectedJob.getIdJobType().equals("1")) {
                            float distance = 0f;

                            if (selectedJob.getAreas() != null) {
                                for (int i = 0; i < selectedJob.getAreas().size(); i++) {
                                    Area area = selectedJob.getAreas().get(i);

                                    if (area.getDist() != null) {
                                        if (i == 0) {
                                            Location locB = new Location("");
                                            locB.setLatitude(Double.parseDouble(area.getLatitude()));
                                            locB.setLongitude(Double.parseDouble(area.getLongitude()));
                                            distance = locA.distanceTo(locB) / 1000;
                                        }


                                        if (Double.parseDouble(area.getDist()) < distance) {
                                            Location locB = new Location("");
                                            locB.setLatitude(Double.parseDouble(area.getLatitude()));
                                            locB.setLongitude(Double.parseDouble(area.getLongitude()));
                                            distance = locA.distanceTo(locB) / 1000;
                                        }
                                    }
                                }
                            }

                            if (distance <= radiusKilometer) {

                            } else {

                            }
                        } else if (selectedJob.getIdJobType().equals("2")) {

                        } else if (selectedJob.getIdJobType().equals("3")) {
                            List<LatLng> areas = new ArrayList<>();
                            for (Area area : selectedJob.getAreas()) {
                                areas.add(new LatLng(Double.parseDouble(area.getLatitude()), Double.parseDouble(area.getLongitude())));
                            }

                            if (PolyUtil.containsLocation(myLocation, areas, true)) {

                            } else {



                                float distance = 0f;

                                if (selectedJob.getAreas() != null) {
                                    for (int i = 0; i < selectedJob.getAreas().size(); i++) {
                                        Area area = selectedJob.getAreas().get(i);

                                        if (area.getDist() != null) {
                                            if (i == 0) {
                                                Location locB = new Location("");
                                                locB.setLatitude(Double.parseDouble(area.getLatitude()));
                                                locB.setLongitude(Double.parseDouble(area.getLongitude()));
                                                distance = locA.distanceTo(locB) / 1000;
                                            }

                                            if (Double.parseDouble(area.getDist()) < distance) {
                                                Location locB = new Location("");
                                                locB.setLatitude(Double.parseDouble(area.getLatitude()));
                                                locB.setLongitude(Double.parseDouble(area.getLongitude()));
                                                distance = locA.distanceTo(locB) / 1000;
                                            }
                                        }
                                    }
                                }

                                if (distance <= 0.5) {

                                } else {


                                }


                            }
                        } else if (selectedJob.getIdJobType().equals("4")) {

                        }


                    }
                }
            })
            .show();
}

public void showLoading() {
    prbLoading.setVisibility(View.VISIBLE);
    lnrNoList.setVisibility(View.GONE);
    rv_gawean_fragment.setVisibility(View.GONE);
}

public void loadObservation() {



    isObservation = true;
    isStoreCount = false;

    if (isMapReady) {
        presenter.getAssignList(GaweanPresenter.OBSERVATION, Double.toString(myLocation.latitude), Double.toString(myLocation.longitude));
        presenter.getApplyList(GaweanPresenter.OBSERVATION, Double.toString(myLocation.latitude), Double.toString(myLocation.longitude));
    }


}

public void loadStoreCount() {

    isObservation = false;
    isStoreCount = true;

    if (isMapReady) {
        presenter.getAssignList(GaweanPresenter.STORE_COUNT, Double.toString(myLocation.latitude), Double.toString(myLocation.longitude));
        presenter.getApplyList(GaweanPresenter.STORE_COUNT, Double.toString(myLocation.latitude), Double.toString(myLocation.longitude));
    }

}

@OnClick(R.id.btnSubmit)
public void onClickSubmit(Button v) {
    if (v.getText().toString().equals("Coba Lagi")) {
        if (ThemeUtil.getThemes() == ThemeUtil.THEME_OBSERVATION) {
            loadObservation();
        } else {
            loadStoreCount();
        }
    } else {
        HomeActivity.startActivity(getActivity());
    }
}

but, i have problem like this, in my recycler view, this is the Log

Process: com.mogawe.mosurvei, PID: 4807
                                                             java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
                                                                   at com.mogawe.mosurveibeta.view.fragment.menu.GaweanFragment.initRV(GaweanFragment.java:215)
                                                                   at com.mogawe.mosurveibeta.view.fragment.menu.GaweanFragment.onCreate(GaweanFragment.java:130)

the error is on this line of code

rv_gawean_fragment.setLayoutManager(llManager);

actually what caused this error, and how to debug it. Maybe just it, i hope you can help me in this error, thanks

Implement a single Java class/interface, which references multiple classes

Problem Statement:
We have multiple class files (~200+), which each implement different methods and some use the methods from each other also to implement their own methods.

We wish to call multiple of these class methods (~20-30) in our code and have them deliver functionality like writing to a UI Web page and reading from a web page.

As we wish to make this process simple, we want a single class/interface which contains all these multiple class references (~200+), and we just need to import/include this single class/interface in our code and then using it to reference all the methods in the class files.

Question:
Is the above possible? If so, how – by using a class or interface or something else?

I have provided examples and information of what we have tried here: Implement multiple classes in the same interface in Java?

Basically, we have tried

  1. Creating a Class which has all the other class declared in it
  2. Creating an interface, which has implementations across the multiple classes (the ~200+ mentioned above)
  3. Implemented a class and an interface

Nope of the ways seem to work.

As a gist of what we want in code, have provided an example below. Example:

I have 2 classes called “ABC_FamilyGivenName” & “ABC_DOBGender“.
I have created an interface Common.

I want to use the methods in both the above classes in my code in class “Application“.

With the current implementation, Java wants me to add an @Override to both the ABC_FamilyGivenName & ABC_DOBGender. This again creates an overhead, if we have ~500 such methods, and will thus need to override all ~500 in each of the c~200 class files??

***INTERFACE***:

public interface Common {
    void ABC_GivenNames();
    void ABC_FamilyNames();
    void ABC_Gender();
    void ABC_BirthDay();
}



***IMPLEMENTATION CLASSES***:

**ABC_FamilyGivenName**
public class ABC_FamilyGivenName extends Base implements Common {

    public void ABC_GivenNames(){
        // Implementation code
    }

    public void ABC_FamilyNames(){
        // Implementation code
    }
}

**ABC_DOBGender**
public class ABC_DOBGender extends Base implements Common {

    public void ABC_Gender(){
        // Implementation code
    }

    public void ABC_BirthDay(){
        // Implementation code
    }
}



**USE IMPLEMENTED CLASS IN CODE**:
public class Application extends Base {

    Common commonClass = new ABC_FamilyGivenName();
    /* *DO I NEED THIS? I THINK I DO, BUT CODE/JAVA SAYS I DO NOT*
     * Common commonClass = new ABC_DOBGender();
     */

    public void ELP_C0050_PassportDetails(){
        commonClass.ABC_GivenNames();
        commonClass.ABC_FamilyNames();
        commonClass.ABC_DOB();
        commonClass.ABC_Gender();
    }
}

RSelenium Website Load

Was able open the browser using RSelenium but website that I am trying to load won’t load

library(RSelenium)
library(XML)

remDr <- remoteDriver(browserName = 'chrome')
remDr$open()

remDr$navigate("http://www.cnn.com")

error says:

    Selenium message:unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"6232.1","isDefault":true},"id":1,"name":"","origin":"://"}
      (Session info: chrome=62.0.3202.94)
      (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)

    Error:   Summary: UnknownError
         Detail: An unknown server-side error occurred while processing the command.
         Further Details: run errorDetails method

I downloaded the necessary requirements and set it up in command line
enter image description here

enter image description here

Error when attempting to run PubSub emulator locally

I want to do some pubsub testing locally so I have done “gcloud components install pubsub-emulator”.

Now when I attempt to do “gcloud beta emulators pubsub start” I get the following error:

ERROR: (gcloud.beta.emulators.pubsub.start) [Errno 8] nodename nor servname provided, or not known
This may be due to network connectivity issues. Please check your network settings, and the status of the service you are trying to reach.

I am using Java version 1.8. Using Java9 wasn’t working for me, and someone recommended I downgrade. I can’t find any mention of this error. My .profile looks like this:

export PATH="$HOME/develop/google-cloud-sdk/bin:$PATH"

My .bashrc looks like:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
export PATH=$JAVA_HOME/bin:$PATH

When I type java -version I get:

java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

How to print a specific line from a list using user’s input as search in java

I have a textfield named searchtext and thats the users input. On button click i search a list with 9126 values imported from a csv file and i want to print the line that has the user’s input on a label.

    public void search(ActionEvent actionEvent) throws IOException{
    ArrayList<String> list=new ArrayList<>();
    Scanner scanner = new Scanner(file);            //I have a file named "something.csv"
    while (scanner.hasNextLine()) {
        list.add(scanner.nextLine());
    }                                               //now i have all 9126 lines in the list
    String search = searchtext.getText().replaceAll("\s", ""); //searchtext is the users input
    if (list.contains(search)){
        //PRINT THE LINE THAT CONTAINS WHAT THE USER WROTE
    }
}

Subsequent acquires on semaphore on the same thread

I’m trying to use a semaphore to lock a thread for a few seconds before it gives up on trying to acquire the lock and carries on. The problem is, I think the semaphore is not actually locking anything. Here’s what I’m trying to do:

Semaphore lock = new Semaphore(1)
lock.acquire();

//Wait until some other thread releases the lock, or until the timeout
lock.tryAcquire(WAIT_INTERVAL, TimeUnit.MILLISECONDS);

//do whatever

I think the problem is: trying to acquire twice from the same thread does not prevent the thread from running if it has already acquired the lock. But I’m not sure. Is that what’s happening?

Thanks guys.