Caused by:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.isDirectory()' on a null object reference
LocalOfficeManager officeManager = LocalOfficeManager.install();
try {
// Start an office process and connect to the started instance (on port 2002).
officeManager.start();
File inputFile = new File("storage/emulated/0/COVID-19/111.pdf");
wordtext = String.valueOf(JodConverter.convert(inputFile));
} catch (OfficeException e) {
e.printStackTrace();
} finally {
// Stop the office process
OfficeUtils.stopQuietly(officeManager);
}
E/AndroidRuntime: FATAL EXCEPTION: main Process: handbook_multi_maker.TJ, PID: 17976 java.lang.RuntimeException: Unable to start activity ComponentInfo{handbook_multi_maker.TJ/TJ.SecondActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.isDirectory()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3107) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3250) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1947) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7032) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.isDirectory()' on a null object reference at org.jodconverter.local.office.LocalOfficeUtils.validateOfficeHome(LocalOfficeUtils.java:339) at org.jodconverter.local.office.LocalOfficeManager$Builder.build(LocalOfficeManager.java:169) at org.jodconverter.local.office.LocalOfficeManager.install(LocalOfficeManager.java:78) at TJ.SecondActivity.initWebView(SecondActivity.java:132) at TJ.SecondActivity.onCreate(SecondActivity.java:104) at android.app.Activity.performCreate(Activity.java:7327) at android.app.Activity.performCreate(Activity.java:7318) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3087) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3250) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1947) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7032) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
You got this error because the default behavior of JODConverter is to auto-detect the office (LibreOffice or Apache OpenOffice) installation you will be working with. In your particular case, the office home directory was not found (thus null).
So, if your office installation is within a custom directory, you can use the officeHome property.
Here's your updated code:
OfficeManager officeManager =
LocalOfficeManager.builder()
.officeHome("Path to your office home")
.install()
.build();
try {
// Start an office process and connect to the started instance (on port 2002).
officeManager.start();
File inputFile = new File("storage/emulated/0/COVID-19/111.pdf");
wordtext = String.valueOf(JodConverter.convert(inputFile));
} catch (OfficeException e) {
e.printStackTrace();
} finally {
// Stop the office process
OfficeUtils.stopQuietly(officeManager);
}
Related
gettoken() throws INVALID_TARGET_VERSION error in Android 10
I used this dependency and this method.
implementation platform('com.google.firebase:firebase-bom:28.4.2')
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-analytics'
FirebaseMessaging.getInstance().subscribeToTopic(topic).addOnCompleteListener((task) -> {
if (!task.isSuccessful()) {
return;
}
});
FirebaseMessaging.getInstance().getToken().addOnCompleteListener((task)-> {
if (!task.isSuccessful()) {
return;
}
// Get new FCM registration token
String token = task.getResult();
});
this is error content
E/FirebaseMessaging: Failed to sync topics. Won't retry sync. INVALID_TARGET_VERSION
D/IMI: =====> Fetching FCM registration token failed java.io.IOException: INVALID_TARGET_VERSION
W/System.err: java.io.IOException: INVALID_TARGET_VERSION
at com.google.firebase.iid.GmsRpc.handleResponse(com.google.firebase:firebase-iid##21.0.1:7)
at com.google.firebase.iid.GmsRpc.lambda$extractResponseWhenComplete$0$GmsRpc(Unknown Source:8)
at com.google.firebase.iid.GmsRpc$$Lambda$0.then(Unknown Source:2)
at com.google.android.gms.tasks.zzc.run(com.google.android.gms:play-services-tasks##17.2.1:3)
at com.google.firebase.iid.FirebaseIidExecutors$$Lambda$0.execute(Unknown Source:0)
at com.google.android.gms.tasks.zzd.zza(com.google.android.gms:play-services-tasks##17.2.1:1)
at com.google.android.gms.tasks.zzr.zzb(com.google.android.gms:play-services-tasks##17.2.1:5)
at com.google.android.gms.tasks.zzw.zza(com.google.android.gms:play-services-tasks##17.2.1:3)
at com.google.android.gms.tasks.zzc.run(com.google.android.gms:play-services-tasks##17.2.1:8)
at com.google.android.gms.cloudmessaging.zzz.execute(Unknown Source:0)
at com.google.android.gms.tasks.zzd.zza(com.google.android.gms:play-services-tasks##17.2.1:1)
at com.google.android.gms.tasks.zzr.zzb(com.google.android.gms:play-services-tasks##17.2.1:5)
at com.google.android.gms.tasks.zzw.zza(com.google.android.gms:play-services-tasks##17.2.1:3)
at com.google.android.gms.tasks.TaskCompletionSource.setResult(com.google.android.gms:play-services-tasks##17.2.1:1)
at com.google.android.gms.cloudmessaging.zzq.zza(com.google.android.gms:play-services-cloud-messaging##16.0.0:9)
at com.google.android.gms.cloudmessaging.zzs.zza(com.google.android.gms:play-services-cloud-messaging##16.0.0:7)
at com.google.android.gms.cloudmessaging.zzf.zza(com.google.android.gms:play-services-cloud-messaging##16.0.0:45)
at com.google.android.gms.cloudmessaging.zzi.handleMessage(Unknown Source:2)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:247)
at android.app.ActivityThread.main(ActivityThread.java:8656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
I followed the example, but I do not understand the content of this error. What problem do I have?
I am recording videos using the camera X library. When i take video for 5 seconds before that (i,e)two seconds if i close the video its crashing with above error.How to handle this run time exception in android cameraX library
E/AndroidRuntime: FATAL EXCEPTION: CameraX-audio encoding thread
Process: .debug, PID: 4625
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:2698)
at androidx.camera.core.VideoCapture.audioEncode(VideoCapture.java:705)
at androidx.camera.core.VideoCapture$1.run(VideoCapture.java:340)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.os.HandlerThread.run(HandlerThread.java:65)
sometimes the below issue
FATAL EXCEPTION: CameraX-video encoding thread
Process: <packagename>, PID: 10794
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.MediaCodec.dequeueOutputBuffer(android.media.MediaCodec$BufferInfo, long)' on a null object reference
at androidx.camera.core.VideoCapture.videoEncode(VideoCapture.java:604)
at androidx.camera.core.VideoCapture$2.run(VideoCapture.java:348)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)
in this samples also not fixed yet
https://github.com/android/camera-samples/issues/2#issuecomment-546812852
By adding a callback to videoCapture.startRecording(videoFile, executor, onVideoSavedCallback); you should be able to handle the exeption in the onError method.
/**
* Define callback that will be triggered after a video has been taken and saved to disk
*/
private VideoCapture.OnVideoSavedCallback onVideoSavedCallback= new VideoCapture.OnVideoSavedCallback() {
#SuppressLint("RestrictedApi")
#Override
public void onVideoSaved(#NonNull File file) {
Log.d("VIDEO_CAPTURE", "Video capture succeeded");
}
#Override
public void onError(int videoCaptureError, #NonNull String message, #Nullable Throwable cause) {
Log.e("VIDEO_CAPTURE", "Video capture failed");
if (cause != null) {
cause.printStackTrace();
Toast.makeText(context,"Video capture failed",Toast.LENGTH_LONG).show();
}
}
};
I'm currently working on my A Level Computer Science controlled assessment, making a Scout Manager App in Android Studio, using Java and XML - none of which I have used before. I'm now working on a n event creator.
I'm trying to create a record, which will show which transport has been selected for which event, however I have run into a problem - the LogCat is giving me the following error:
04-02 15:25:42.663 18482-18482/com.example.atomi.scoutmanagerprototype E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.atomi.scoutmanagerprototype, PID: 18482
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:4761)
at android.view.View$PerformClick.run(View.java:19767)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5310)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:4761)
at android.view.View$PerformClick.run(View.java:19767)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5310)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.example.atomi.scoutmanagerprototype/databases/ScoutManager.db
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1158)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1202)
at com.example.samogonovsky.scoutmanager.databaseHandler.getRandomTransport(databaseHandler.java:649)
at com.example.samogonovsky.scoutmanager.frmCreateEvent2.saveAndExit(frmCreateEvent2.java:528)
However, I have not closed the cursor in either of these two places.
Here is the code in the "databaseHandler" class:
//Select a random mode of transport
public Cursor getRandomTransport()
{
Cursor cursor=db.query(TABLE_TRANSPORT, null, null, null, null, null, "RANDOM()limit 1");
if (cursor!=null&&cursor.moveToFirst())
{
cursor.moveToFirst();
}
else
{
cursor=null;
}
return cursor;
}
And here is the code in the "frmAddEvent2" class:
double TotalTransportCost;
if (providingtransport==true)
{
int peopletotransport=noOfPeople;
TotalTransportCost = 0;
do
{
int eventtransportid=createEventTransportId();
Cursor ModeOfTransport = DatabaseHandler.getRandomTransport();
if (ModeOfTransport.moveToFirst()) {
int transportid=ModeOfTransport.getInt(ModeOfTransport.getColumnIndex(
DatabaseHandler.COLUMN_TRID));
double PriceForHiring = ModeOfTransport.getDouble(ModeOfTransport.getColumnIndex(
DatabaseHandler.COLUMN_HCOST));
double PricePerMile = ModeOfTransport.getDouble(ModeOfTransport.getColumnIndex(
DatabaseHandler.COLUMN_MCOST));
int NoOfSeats = ModeOfTransport.getInt(ModeOfTransport.getColumnIndex(
DatabaseHandler.COLUMN_SEATNO));
double ModeCost = ((PricePerMile*distancefrombase)+PriceForHiring);
eventTransportDetails eventtransport = new eventTransportDetails(eventtransportid,
id, transportid);
DatabaseHandler.createEventTransport(eventtransport);
BigDecimal bigdecimalmodecost=new BigDecimal(ModeCost);
BigDecimal bigdecimalpropermodecost=((bigdecimalmodecost.setScale(2,bigdecimalmodecost.ROUND_DOWN)));
double propermodecost=bigdecimalpropermodecost.doubleValue();
TotalTransportCost = TotalTransportCost + propermodecost;
peopletotransport = (peopletotransport-NoOfSeats);
ModeOfTransport.close();
}
else
{
Toast.makeText(
context,
"Error - you have not added any lunches, therefore food " +
"cannot be added.",
Toast.LENGTH_SHORT
).show();
return;
}
}
while (peopletotransport>0);
}
else
{
TotalTransportCost=0;
}
I was wondering if anybody could point me in the right direction?
Also, feel free to suggest any improvements to my question - as stated, a lot of this is new to me, so I may have left out some pretty important material.
Ok, so as it turns out, I put "db.close();" after a few of the functions in databaseHandler - by removing all of these, I fixed the problem. If you think this question would be better off not on the site, let me know and I'll delete it. Thanks though to all who commented.
This question already has answers here:
How can I fix 'android.os.NetworkOnMainThreadException'?
(66 answers)
Closed 3 years ago.
I'm trying to check if I can establish a connection to my TCP server with this simple method:
public static boolean serverListening()
{
Socket s = null;
try
{
s = new Socket("192.168.42.213", 80);
return true;
}
catch (Exception e)
{
Log.d("SocketException", "Exception",e);
return false;
}
finally
{
if(s != null)
try {s.close();}
catch(Exception e){}
}
}
My server is already working as I'm able to connect to it with chrome inside the emulator so the problem must lie in my code.
Im getting the following exception if I try to run the code:
SocketException
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1513)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:389)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:621)
at java.net.Socket.connect(Socket.java:570)
at java.net.Socket.<init>(Socket.java:450)
at java.net.Socket.<init>(Socket.java:218)
at com.example.batterymonitor.MainActivity.serverListening(MainActivity.java:104)
at com.example.batterymonitor.MainActivity.onCreate(MainActivity.java:58)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Thank you very much for your help!
In android you can't run network related actions on the main thread - you need to run them on a different thread, for example:
Thread mThread = new Thread(new Runnable() {
#Override
public void run() {
try {
//Put your code that you want to run in here(check your connection for example)
} catch (Exception e) {
e.printStackTrace();
}
}
});
mThread.start
This question already has answers here:
Exception 'open failed: EACCES (Permission denied)' on Android
(34 answers)
Closed 6 years ago.
Currently I have this code where I copy paste from here into my source code. But due to some reason unknown to me, the OutputStreamWriter keep giving IOException. And I'm clueless on what cause this and how to fix it. Please help. Below is my code.
public void generateNoteOnSD(){// create a File object for the parent directory
try {
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File myFile = new File(path, "mytextfile.txt");
FileOutputStream fOut = new FileOutputStream(myFile,true);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append("the text I want added to the file");
Log.d("Save File Test : ","Success");
myOutWriter.close();
fOut.close();
}
catch (IOException e) {
//do something if an IOException occurs.
Log.d("Save File Test : ","Failed");
}
}
I have already included
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in the manifest, and also running the code in AsyncTask - onPostExecute and on AVD with Lollipop version.
My stacktrace:
08-28 11:22:52.788 30478-30478/com.example.azrie.dummyvoice E/YOUR_APP_LOG_TAG: I got an error
java.io.FileNotFoundException: /storage/emulated/0/Download/mytextfile.txt: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at com.example.azrie.dummyvoice.ReadHTML.generateNoteOnSD(ReadHTML.java:126)
at com.example.azrie.dummyvoice.ReadHTML.onPostExecute(ReadHTML.java:78)
at com.example.azrie.dummyvoice.ReadHTML.onPostExecute(ReadHTML.java:37)
at android.os.AsyncTask.finish(AsyncTask.java:651)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at com.example.azrie.dummyvoice.ReadHTML.generateNoteOnSD(ReadHTML.java:126)
at com.example.azrie.dummyvoice.ReadHTML.onPostExecute(ReadHTML.java:78)
at com.example.azrie.dummyvoice.ReadHTML.onPostExecute(ReadHTML.java:37)
at android.os.AsyncTask.finish(AsyncTask.java:651)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
private static final String FILE_NAME="score.txt";
BufferedOutputStream o;
try {
o = new BufferedOutputStream(new FileOutputStream(new File(getFilesDir(),FILE_NAME)));
String s = //here write what you want to write to the file . its got to be string to work
o.write(s.getBytes());
o.close();
}catch (FileNotFoundException e ){
}catch (IOException e){
}
for me its work for every time and its not opening new file every time.
if you want to see it in action serch FightWithMath in the play store. you will need to fully restart the app after first login and its writing in the main screen and while the game running every time you win