I tried to run a word count program in eclipse. in the browser the output directories are being created but i am not getting any out put. I am getting the following error. plz help me out. please. I am struct at the last point.
I gave the following command to execute the program.
hduser#niki-B85M-D3H:/home/niki/workspace$ hadoop jar wordcount.jar WordCount /user/hadoop/dir1/file.txt wordcountoutput
The output file named wordcountoutput is created but the error is displayed as follows.
I tried to run a word count program in eclipse. in the browser the output directories are being created but i am not getting any out put. I am getting the following error. plz help me out. please. I am struck at the last point.
I gave the following command to execute the program.
hduser#niki-B85M-D3H:/home/niki/workspace$ hadoop jar wrd.jar WordCount /user/hduser/outputwc /user/hduser/outputwc/
The output file named wordcountoutput is created but the error is displayed as follows.
5/12/24 15:15:46 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at WordCount.run(WordCount.java:29)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:84)
at WordCount.main(WordCount.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
this is the exception i am getting now at the final step
WordCount.java
import java.io.IOException;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider.Text;
public class WordCount extends Configured implements Tool{
#Override
public int run(String[] args) throws Exception {
if(args.length<2){
System.out.println("plz give input and output directories");
return -1;
}
JobConf conf = new JobConf();
//conf.setJarByClass(WordCount.class);
conf.setJar("wrd.jar");
FileInputFormat.setInputPaths(conf,new Path(args[1]));
FileOutputFormat.setOutputPath(conf,new Path(args[2]));
conf.setMapperClass(WordMapper.class);
conf.setReducerClass(WordReducer.class);
conf.setMapOutputKeyClass(Text.class);
conf.setMapOutputValueClass(IntWritable.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
JobClient.runJob(conf);
return 0;
}
public static void main(String args[]) throws Exception{
int exitCode =ToolRunner.run(new WordCount(), args);
System.exit(exitCode);
}
}
Word Reducer.java
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
public class WordReducer extends MapReduceBase implements Reducer<Text,IntWritable,Text,IntWritable>{
#Override
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter r)
throws IOException {
int count=0;
while(values.hasNext()){
IntWritable i= values.next();
count+=i.get();
}
output.collect(key,new IntWritable(count));
}
}
WordMapper.java
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
public class WordMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
#Override
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter r)
throws IOException {
String s = value.toString();
for(String word:s.split(" ")){
if(word.length()>0){
output.collect(new Text(word), new IntWritable(1));
}
}
}
}
Try this out:
public static void main(String args[]) throws Exception{
int exitCode =ToolRunner.run(new Configuration(), new WordCount(), args);
System.exit(exitCode);}
according to this
Related
When I try to run the simplest PortableRunner pipeline on Java, I get the error:
Exception in thread "main" java.lang.RuntimeException: The Runner experienced the following error during execution:
java.io.IOException: error=2, No such file or directory
at org.apache.beam.runners.portability.JobServicePipelineResult.propagateErrors(JobServicePipelineResult.java:176)
at org.apache.beam.runners.portability.JobServicePipelineResult.waitUntilFinish(JobServicePipelineResult.java:117)
at org.apache.beam.examples.PythonExternal.runWordCount(PythonExternal.java:74)
at org.apache.beam.examples.PythonExternal.main(PythonExternal.java:81)
However, I do not read any files anywhere in the pipeline or I do not sink to anywhere. My arguments are
--runner=PortableRunner --jobEndpoint=localhost:8099
and code
package org.apache.beam.examples;
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.coders.StringUtf8Coder;
import org.apache.beam.sdk.options.*;
import org.apache.beam.sdk.schemas.Schema;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.values.Row;
import java.util.Arrays;
import java.util.List;
public class Simplest {
public static final Schema SCHEMA =
Schema.of(
Schema.Field.of("sentence", Schema.FieldType.STRING),
Schema.Field.of("count", Schema.FieldType.INT32));
public interface WordCountOptions extends PipelineOptions {
/** Set this option to specify Python expansion service URL. */
#Description("URL of Python expansion service")
String getExpansionService();
void setExpansionService(String value);
}
static void runWordCount(WordCountOptions options){
final List<String> LINES = Arrays.asList(
"To be, or not to be: that is the question: ",
"Whether 'tis nobler in the mind to suffer ",
"The slings and arrows of outrageous fortune, ",
"Or to take arms against a sea of troubles, ");
Pipeline p = Pipeline.create(options);
p.apply("ReadLines", Create.of(LINES)).setCoder(StringUtf8Coder.of())
.apply(ParDo
.of(new DoFn<String, Row>() {
#ProcessElement
public void processElement(#Element String element, OutputReceiver<Row> out, ProcessContext c) {
// In our DoFn, access the side input.
out.output(Row.withSchema(SCHEMA)
.withFieldValue("sentence", element)
.withFieldValue("count", 1)
.build());
}
}))
.setRowSchema(SCHEMA);
p.run().waitUntilFinish();
}
public static void main(String[] args) {
WordCountOptions options =
PipelineOptionsFactory.fromArgs(args).withValidation().as(WordCountOptions.class);
runWordCount(options);
}
}
Although the manual suggests adding --environment_type=LOOPBACK, I also get error as
Class interface org.apache.beam.examples.PythonExternal$WordCountOptions missing a property named 'environment_type'.
Beam Version: 2.40.0
I started the JobService endpoint docker run --net=host apache/beam_flink1.14_job_server:latest as suggested.
Any suggestions?
I am trying to run the following code with eclipse but it will give me the error: "The method when() is undefined for the type LastLabTest". I have imported the libraries but still it gives me that error. I am using eclipse with junit5.
import io.restassured.RestAssured;
import io.restassured.RestAssured.*;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import io.restassured.http.ContentType;
import io.restassured.matcher.RestAssuredMatchers.*;
import io.restassured.specification.RequestSpecification;
import org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.jupiter.api.Test;
class LastLabTest {
private RequestSpecification specification;
#BeforeClass
public void inItSpec() {
specification = new RequestSpecBuilder()
.setContentType(ContentType.JSON)
.setBaseUri("http://openlibrary.org/")
.addFilter(new RequestLoggingFilter())
.addFilter(new ResponseLoggingFilter())
.build();
}
#Test
public void getByName() {
when().get("https://swapi.co/api/people/1")
.then().log().all()
.statusCode(200)
.and()
.body("name", equals("Luke Skywalker"));
}
}
The keyword static is missing in the line
import io.restassured.RestAssured.*;
=>
import static io.restassured.RestAssured.*;
keyword static is missing in import io.restassured.RestAssured.;
correct : import static io.restassured.RestAssured.;
I want to create a Movie Player in javafx using eclipse.My code is compile successfully but it gives run time error.I tried using different file path also.
But it not resolved the error.
My code is
package Player3;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MediaPlayer3 extends Application{
public static void main(String args[])
{
launch(args);
}
public void start(Stage stage) throws Exception {
Group root = new Group();
Media media =new Media("file:////C://Kaise.MP4");
MediaPlayer player4=new MediaPlayer(media);
MediaView view = new MediaView(player4);
root.getChildren().add(view);
Scene scene =new Scene(root,400,400,Color.BLACK);
stage.setScene(scene);
stage.show();
player4.play();
}
}
The error is
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
java.lang.RuntimeException: Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
As #Sergei Sirik mentioned this is JavaFX and not 'pure' java. Anyway reading the documentation of Media class for the constructor(String source) you will see :
The source must represent a valid URI and is immutable. Only HTTP, FILE, and JAR URLs are supported. If the provided URL is invalid then an exception will be thrown
So I will suggest first to create a File object ( to be able to check file permissions for read write etc ) and after that just pass the mediaFile.toURI().toString() to the Media class constructor and it will open.
Edit :
I guess you will use a FileChooser in future in order to load your video so it will make the file creation and handling much easier.
I had test the code below and it loads successfully my videos on my computer.
import java.io.File;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String args[]) {
launch(args);
}
public void start(Stage stage) throws Exception {
Group root = new Group();
FileChooser fc = new FileChooser();
File x = fc.showOpenDialog(null);
Media media = new Media(x.toURI().toString());
MediaPlayer player4 = new MediaPlayer(media);
MediaView view = new MediaView(player4);
root.getChildren().add(view);
Scene scene = new Scene(root, 400, 400, Color.BLACK);
stage.setScene(scene);
stage.show();
player4.play();
}
}
If you have any error like :
MediaException: MEDIA_UNSUPPORTED : Unrecognized file signature!
It's probably cause you alter the file signature by hand or try to play an unsupported file format like mkv.
I am trying to get the last known location using Google API client, but I have an issue with it being incompatible. Can anyone point out what did I miss?
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, OnConnectionFailedListener,
ConnectionCallbacks{
private GoogleMap mMap;
private GoogleApiClient mGoogleApiClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// getting incompatible issue in below line
mGoogleApiClient = new GoogleApiClient.Builder(this);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
Try this.
mGoogleApiClient = new GoogleApiClient.Builder(this).build();
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class multicheckbox {
public static void main(String[] args) {
WebDriver driver= new FirefoxDriver();
driver.get("http://www.jobserve.com/au/en/Job-Search/");
driver.findElement(By.xpath(".//*[#id='ddcl-selInd']/span/span")).click();
driver.findElement(By.xpath(".//*[#id='ddcl-selInd-ddw']/div/div[1]/label")).click();
int selection=9;
Xls_Reader ob1=new Xls_Reader("C:\\Users\\saurovs\\workspace\\New\\java\\firsttest.xlsx");// i am getting error on this line
String ob2= ob1.getCelldata("selenium","indexvalue",2);
String selections[]= ob2.split(",");
String xpath_start= ".//*[#id='ddcl-selInd-ddw']/div/div[";
String xpath_end="]/label";
for(int i=1; i<selections.length;i++)
driver.findElement(By.xpath(xpath_start + selections[i] + xpath_end)).click();
}}
i have added the full script please help me how to resolve it.
Xls_Reader cannot be resolved to a type
Xls_Reader cannot be resolved to a type