My app stopped logcat error - logcat

I have this error and i don't know why!
04-28 09:26:55.935: E/AndroidRuntime(1437): FATAL EXCEPTION: main
04-28 09:26:55.935: E/AndroidRuntime(1437): Process:
com.neurondigital.HighwaySpeed, PID: 1437
04-28 09:26:55.935: E/AndroidRuntime(1437):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.neurondigital.HighwaySpeed/com.neurondigital.HighwaySpeed.HighwaySpeed}:
java.lang.NullPointerException
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.app.ActivityThread.access$800(ActivityThread.java:135)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.os.Handler.dispatchMessage(Handler.java:102)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.os.Looper.loop(Looper.java:136)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.app.ActivityThread.main(ActivityThread.java:5017)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
java.lang.reflect.Method.invokeNative(Native Method)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
java.lang.reflect.Method.invoke(Method.java:515)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
dalvik.system.NativeStart.main(Native Method)
04-28 09:26:55.935: E/AndroidRuntime(1437): Caused by:
java.lang.NullPointerException
04-28 09:26:55.935: E/AndroidRuntime(1437): at
com.neurondigital.HighwaySpeed.HighwaySpeed.onCreate(HighwaySpeed.java:40)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.app.Activity.performCreate(Activity.java:5231)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-28 09:26:55.935: E/AndroidRuntime(1437): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-28 09:26:55.935: E/AndroidRuntime(1437): ... 11 more
This is the code:
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.Display;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
public class HighwaySpeed extends Activity {
Surface view;
WakeLock WL;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//wake-lock
PowerManager PM = (PowerManager)getSystemService(Context.POWER_SERVICE);
WL = PM.newWakeLock(PowerManager.FULL_WAKE_LOCK, "Graphics");
WL.acquire();
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
if(rotation == 0)
view.default_lanscape = true;
if(rotation == 180)
view.default_lanscape = true;
if(rotation == 90)
view.default_lanscape = false;
if(rotation == 270)
view.default_lanscape = false;
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyDown(keyCode, event);
if(keyCode == KeyEvent.KEYCODE_BACK){
view.back();
return false;
}
return false;
}
protected void onPause(){
super.onPause();
view.pause();
WL.release();
}
protected void onResume(){
super.onResume();
view.resume();
WL.acquire();
}
#Override
protected void onDestroy() {
super.onDestroy();
WL.release();
}
}

At HighwaySpeed.java:40 there's a NullPointerException
If you attach the code it's easy to resolve the problem.
EDIT:
You have to write view = new SurfaceView(this); at the beginin of onCreate method to avoid the NullPointerException.
The main problem is that you don't initialize the variable, but there is other errors in the code, for example the class Surface hasn't got a default_lanscape attribute and you're triying to initialize it in view.default_lanscape = true;

Related

IllegalArgumentException while starting Wildfly-Swarm [provided custom Main method]

A weird exception is throwing while I'm attempting to run my wildfly-swarm instance. Following is the error that I'm getting;
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.wildfly.swarm.bootstrap.Main.invoke(Main.java:78)
at org.wildfly.swarm.bootstrap.Main.run(Main.java:53)
at org.wildfly.swarm.bootstrap.Main.main(Main.java:44)
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:80)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:95)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:72)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.access$000(JAXRSArchiveImpl.java:41)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl$ApplicationHandler.handle(JAXRSArchiveImpl.java:249)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.invokeHandlers(MemoryMapArchiveBase.java:238)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.addAsset(MemoryMapArchiveBase.java:185)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.add(MemoryMapArchiveBase.java:126)
at org.jboss.shrinkwrap.impl.base.ArchiveBase.add(ArchiveBase.java:376)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.add(MemoryMapArchiveBase.java:151)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.add(ContainerBase.java:141)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibrary(ContainerBase.java:1729)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibraries(ContainerBase.java:1928)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibraries(ContainerBase.java:1941)
at org.wildfly.swarm.spi.api.DependenciesContainer.addAllDependencies(DependenciesContainer.java:34)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.addPackageResources(FSIndexerBootStrap.java:78)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.bootUpApplication(FSIndexerBootStrap.java:94)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.main(FSIndexerBootStrap.java:109)
... 7 more
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.wildfly.swarm.bootstrap.Main.invoke(Main.java:78)
at org.wildfly.swarm.bootstrap.Main.run(Main.java:53)
at org.wildfly.swarm.bootstrap.Main.main(Main.java:44)
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:80)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:95)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:72)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.access$000(JAXRSArchiveImpl.java:41)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl$ApplicationHandler.handle(JAXRSArchiveImpl.java:249)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.invokeHandlers(MemoryMapArchiveBase.java:238)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.addAsset(MemoryMapArchiveBase.java:185)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.add(MemoryMapArchiveBase.java:126)
at org.jboss.shrinkwrap.impl.base.ArchiveBase.add(ArchiveBase.java:376)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.add(MemoryMapArchiveBase.java:151)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.add(ContainerBase.java:141)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibrary(ContainerBase.java:1729)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibraries(ContainerBase.java:1928)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibraries(ContainerBase.java:1941)
at org.wildfly.swarm.spi.api.DependenciesContainer.addAllDependencies(DependenciesContainer.java:34)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.addPackageResources(FSIndexerBootStrap.java:78)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.bootUpApplication(FSIndexerBootStrap.java:94)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.main(FSIndexerBootStrap.java:109)
... 7 more
I had used a custom Main method. Following is the code for my Main method;
public final class FSIndexerBootStrap {
private void addDependencies ( JAXRSArchive archive ) {
/*
* Collection< String > suppliedDependencies =
* ResearchSuppliedDependenciesConfigurationReader
* .getSuppliedDependencies();
*
* if ( CollectionUtils.isNotEmpty( suppliedDependencies ) ) {
*
* suppliedDependencies.stream().forEach( suppliedDependency -> { try {
* archive.addDependency( ( String ) suppliedDependency ); } catch (
* Exception e ) { // TODO Auto-generated catch block
* e.printStackTrace(); } } ); }
*/
}
private void addSystemProperties () {
String logFileAbsoluteName = ResearchLoggingConfigurationReader.getLogFileAbsoluteName();
if ( StringUtils.isNotBlank( logFileAbsoluteName ) ) {
System.setProperty( "research.log", logFileAbsoluteName );
}
}
private void addPackageResources ( JAXRSArchive archive ) throws IllegalArgumentException, Exception {
if ( !Objects.equals( null, archive ) ) {
// archive.addPackages( true, "com/research/fsindexer" );
archive.addResource( FSIndexerRestApplication.class ).addResource( RESTTest.class )
.addResource( FileIndexerService.class )
.addAsWebInfResource(
new ClassLoaderAsset( "META-INF/beans.xml", FSIndexerBootStrap.class.getClassLoader() ),
"classes/META-INF/beans.xml" )
.addAllDependencies();
}
}
#ExceptionHandled
#Logged
public void bootUpApplication () throws Exception {
addSystemProperties();
final Swarm SWARM = new Swarm( true );
final JAXRSArchive DEPLOYMENT = ShrinkWrap.create( JAXRSArchive.class );
DEPLOYMENT.as( TopologyArchive.class );
addPackageResources( DEPLOYMENT );
addDependencies( DEPLOYMENT );
SWARM.start();
SWARM.deploy( DEPLOYMENT );
}
/**
* #param args
* #throws Exception
*/
public static void main ( String... args ) throws Exception {
FSIndexerBootStrap fsBootStrap = new FSIndexerBootStrap();
fsBootStrap.bootUpApplication();
}
}
The exception is throwing from the addAllDependencies() method call of the JAXRSArchive. I'd tried a debugging but can't figure out the real issue.

Login failed for user 'sa'. ClientConnectionId:c227dc88-59c6-4602-bfd7-f87c994ea995

I've looked in the internet for the error
Login failed for user 'sa'
And followed the solutions but I still get it.
Here is my code:
package model.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionDB {
Connection conn;
String user="sa";
String pass="12345678";
String url = "jdbc:sqlserver://localhost:1434;instance=KID\\SQL;databaseName=QLDTTN";
public Connection getConnectMySQL(){
//nạp driver
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
System.out.println("Không thể nạp driver");
// TODO Auto-generated catch block
e.printStackTrace();
}
//tạo chuỗi kết nối conn
try {
conn = DriverManager.getConnection(url, user,pass);
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("Sai tham số kết nối");
e.printStackTrace();
}
return conn;
}
public static void main(String[] args) {
ConnectionDB c = new ConnectionDB();
System.out.println(c.getConnectMySQL());
}
}
and this is the error detail:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. ClientConnectionId:c227dc88-59c6-4602-bfd7-f87c994ea995
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2908)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at model.dao.ConnectionDB.getConnectMySQL(ConnectionDB.java:24)
at model.dao.ConnectionDB.main(ConnectionDB.java:36)
null
I'm pretty new in JSP and SQL server (I use SQl server 2012).
Thanks a lot

cameltest case with bean

In my java class i have something like below:
from("direct:dcrm:input")
.routeId("dcrm-route"
.convertBodyTo(Message.class)
.setHeader(
"recipientListHeader",
simple("activemq:"+rdvrQueueName+ ".${body.controllerID}?jmsMessageType=Text&timeToLive="
+ rdvrMessageTimeToLive
+ "&deliveryPersistent=" + deliveryPersistent))
.choice()
.when(simple("${body.messageType} == 'rdvr'"))
.bean(new DcrmMessageHandler(), "process")
.marshal(requestMessage)
.recipientList(header("recipientListHeader"))
.onPrepare(new MesssageProcessor()).parallelProcessing()
.end()
.setBody(constant(StatusCode.SUCCESS))
.otherwise()
.endChoice();
while writing Junit i am doint like this :
#Test
public void testSendMatchingMessage() throws Exception {
String expectedBody = "<matched/>";
resultEndpoint.expectedBodiesReceived(expectedBody);
template.sendBodyAndHeader(expectedBody, "recipientListHeader", 0);
resultEndpoint.assertIsSatisfied();
}
#Override
protected RouteBuilder createRouteBuilder() throws Exception {
//return new DcrmOutboundRoute();
return new RouteBuilder() {
#Override
public void configure() throws Exception {
// TODO Auto-generated method stub
from("direct:dcrm:input")
.filter(header("recipientListHeader").isEqualTo(constant(StatusCode.SUCCESS)))
.bean(new DcrmMessageHandler(), "process").to("mock:result");
}
};
}
But I am getting the bellow error:
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/NoResultException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
Check your classpath or your Maven dependencies, in particular the one referencing JPA (javax.persistence). You should have a dependency with groupId javax.persistence and probably artifactId persistence-api, replace it by org.hibernate.javax.persistence or org.eclipse.persistence dependency.

Error while connecting to MySql database using mapreduce job

I was trying the following code for connecting to a mysql database using a map-reduce job. I am facing the following error which is posted below. I have placed checkpoints in my code
which indicate that the part of the job till the job is actually run is run correctly, afterwards the job fails...
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
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.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.SequenceFileOutputFormat;
import org.apache.hadoop.mapred.TextOutputFormat;
import org.apache.hadoop.mapred.lib.db.DBConfiguration;
//import org.apache.hadoop.mapred.lib.db.DBInputFormat;
import org.apache.hadoop.mapred.lib.db.DBInputFormat;
import org.apache.hadoop.mapred.lib.db.DBOutputFormat;
import org.apache.hadoop.mapred.lib.db.DBWritable;
public class TweetWordCount {
public static class TweetWordCountMapper extends MapReduceBase implements
Mapper<LongWritable, GetTweets, Text, IntWritable> {
private final static IntWritable intTwordsCount = new IntWritable(1);
private Text strTwoken = new Text();
public void map(LongWritable key, GetTweets value,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOException {
System.out.println("checkpoint4");
GetTweets tweets = new GetTweets();
tweets.strTweet = value.strTweet;
//TwitterTokenizer twokenizer = new TwitterTokenizer();
//List<String> twokens = twokenizer.twokenize(value.strTweet.toString());
output.collect(new Text(value.strTweet.toString()), intTwordsCount);
System.out.println("checkpoint5");
}
}
public static class TweetWordCountReducer extends MapReduceBase implements
Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOException {
System.out.println("checkpoint6");
int intTwokenCount = 0;
while (values.hasNext()) {
intTwokenCount += values.next().get();
}
output.collect(key, new IntWritable(intTwokenCount));
System.out.println("checkpoint6");
}
}
public static void main(String[] args) throws Exception {
System.out.println("checkpoint1");
JobConf twokenJobConf = new JobConf(new Configuration(),TweetWordCount.class);
//JobConf twokenJobConf = new JobConf(TweetWordCount.class);
twokenJobConf.setJobName("twoken_count");
twokenJobConf.setInputFormat(DBInputFormat.class); //Set input format here
twokenJobConf.setOutputFormat(TextOutputFormat.class);// Sets the output format
Object out = new Path("twokens");
twokenJobConf.setMapperClass(TweetWordCountMapper.class);
twokenJobConf.setCombinerClass(TweetWordCountReducer.class);
twokenJobConf.setReducerClass(TweetWordCountReducer.class);
twokenJobConf.setOutputKeyClass(Text.class);
twokenJobConf.setOutputValueClass(IntWritable.class);
DBConfiguration.configureDB(twokenJobConf, "com.mysql.jdbc.Driver",
"jdbc:mysql://localhost/test", "root", "root"); //Specifies the DB configuration
String[] fields = {"Tweet"}; //Specifies the Fields to be fetched from DB
DBInputFormat.setInput(twokenJobConf, GetTweets.class, "NewGamil",
null /* conditions */, "Tweet", fields); // Specifies the DB table and fields
//SequenceFileOutputFormat.setOutputPath(twokenJobConf, (Path) out);
FileOutputFormat.setOutputPath(twokenJobConf, (Path) out);
System.out.println("checkpoint2");
JobClient.runJob(twokenJobConf);
System.out.println("checkpoint3");
}
public static class GetTweets implements Writable, DBWritable {
String strTweet;
public GetTweets() {
}
public void readFields(DataInput in) throws IOException {
System.out.println("checkpoint 2a");
this.strTweet = Text.readString(in);
}
public void readFields(ResultSet resultSet) throws SQLException {
System.out.println("checkpoint 3a");
// this.id = resultSet.getLong(1);
this.strTweet = resultSet.getString(1);
}
public void write(DataOutput out) throws IOException {
}
public void write(PreparedStatement stmt) throws SQLException {
}
}
}
rv#ramanujan:~$ hadoop jar Twit.jar
Warning: $HADOOP_HOME is deprecated.
checkpoint1
checkpoint2
13/03/22 17:16:12 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
13/03/22 17:16:12 INFO mapred.JobClient: Cleaning up the staging area hdfs://localhost:54310/home/rv/hadoopfiles/mapred/staging/rv/.staging/job_201303221600_0008
Exception in thread "main" java.lang.RuntimeException: Error in configuring object
at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:93)
at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:64)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:117)
at org.apache.hadoop.mapred.JobConf.getInputFormat(JobConf.java:575)
at org.apache.hadoop.mapred.JobClient.writeOldSplits(JobClient.java:981)
at org.apache.hadoop.mapred.JobClient.writeSplits(JobClient.java:973)
at org.apache.hadoop.mapred.JobClient.access$600(JobClient.java:172)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:889)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:842)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:416)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1059)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:842)
at org.apache.hadoop.mapred.JobClient.submitJob(JobClient.java:816)
at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:1253)
at TweetWordCount.main(TweetWordCount.java:107)
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:616)
at org.apache.hadoop.util.RunJar.main(RunJar.java:156)
Caused by: java.lang.reflect.InvocationTargetException
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:616)
at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:88)
... 20 more
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.hadoop.mapred.lib.db.DBInputFormat.configure(DBInputFormat.java:271)
... 25 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:188)
at org.apache.hadoop.mapred.lib.db.DBConfiguration.getConnection(DBConfiguration.java:123)
at org.apache.hadoop.mapred.lib.db.DBInputFormat.configure(DBInputFormat.java:266)
... 25 more
Make sure you use -libjars in commands. like the following :
bin/hadoop jar wordcount.jar org.myorg.DBCountPageView -libjars mysql-connector-java-5.1.26-bin.jar
Please reference http://hadoop.apache.org/docs/r1.2.1/mapred_tutorial.html's usage part
Not sure what the scope of your app is (learning, dev, etc.) but I would suggest to use Sqoop to interact with a relational database such as MySQL.

using java mail api to notify the registered user

actually i am try to notify the user who is registered on my application by sending him an email message and using following code but continuously it gives the exception java.lang.ClassFormatError how can i get rid of this exception. here is the exception and code
Exception:
Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in
method that is not native or abstract in class file javax/mail/MessagingException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: SendMailTLS. Program will exit.
Code is:
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMailTLS {
public static void main(String[] args) {
final String username = "username#gmail.com";
final String password = "password";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from-email#gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("to-email#gmail.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
Do you have javaee.jar or j2ee.jar in your CLASSPATH? If so, get rid of it.

Resources