I am writing an android application that takes in a string, read in by a bar code reader, and then when a particular button press occurs, it will send that string to the database and set their values either to "in stock" or "out of stock". I have not been able to find anything on this except for jackcesss, which does not seem to have any really good documentation on it. I cannot even get it to open the file with their example code. The code looks like this:
try {
Database db = Database.open(new File("sdcard/download/Inventory-1.mdb"));
db.close();
} catch (IOException e) {
new AlertDialog.Builder(CheckInActivity.this).setTitle("CRITICAL ERROR").setMessage("DATABASE FILE NOT FOUND. Please check your wireless connection").setPositiveButton("OK",null).show();
e.printStackTrace();
}
When I run this code on my phone I get a force close (I run it on my phone each time to avoid emulator issues,also I am also try to make it work locally before I attempt to make it a remote file) However if I change the location of the file to something I know does not exist, it will catch it and pop up the dialog box that I specified. I tried this with and without closing the file, with throws and the try and catch, nothing seems to work. So what am I missing here?
How do you know the database open was unsuccessful? I'd put in an explicit indication to hit me over the head:
try {
Database db = Database.open(new File("sdcard/download/Inventory-1.mdb"));
new AlertDialog.Builder(CheckInActivity.this).setTitle("SUCCESS").setMessage("DATABASE WAS OPENED SUCCESSFULLY. ").setPositiveButton("OK",null).show(); db.close();
} catch (IOException e) {
new AlertDialog.Builder(CheckInActivity.this).setTitle("CRITICAL ERROR").setMessage("DATABASE FILE NOT FOUND. Please check your wireless connection").setPositiveButton("OK",null).show();
e.printStackTrace();
}
Related
I have created an application which is working as a launcher. In that application I have opening various other apps. In that app I want to clear all the data(i.e login details, search history) of other application to be removed on click of a button.
PackageManager pm = getPackageManager();
Method[] methods = pm.getClass().getDeclaredMethods();
for (Method m:methods){
if(m.getName().equals("freeStorage")){
try{
long desiredFreeStorage = Long.MAX_VALUE;
m.invoke(pm,desiredFreeStorage,null);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
Using the above code, I am able to delete the cache but not able to delete the data of other apps.
Please provide me a solution for that.
Sorry for my bad english.
Its normal behavior. you can't delete data that belongs to other Apps via your app. Files that contain data are private and only accessible by Apps that own them or shared by App.
For example, most of the Apps use SharedPreference as private files to save data for later use. So, its senseless if other Apps are allowed to delete that data.
I have a electronic phone book application with MySql, everything works just fine in my Eclipse, BUT... when i export runnable jar file, when i run my program everything works fine except that one of my JFrame dont want to show (but it show only in eclipse. no erorrs no nothing, i dont know what to do) ...i talk about my frame where the user can add data to database.
my code for showing that JFrame is this
if (conectat) {
try {
PaginaAdd frameAdd = new PaginaAdd();
if (VariabileGlobale.pagAdd == "NU") {
VariabileGlobale.pagAdd = "DA";
// sa aiba iconita
try {
frameAdd.setIconImage(
ImageIO.read(getClass().getResourceAsStream("/data-add-icon.png")));
} catch (IOException e) {
e.printStackTrace();
}
// terminare sa aiba iconita
frameAdd.setLocationRelativeTo(null);
frameAdd.setVisible(true);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
JOptionPane.showMessageDialog(null, "You are not connected to database!", " Electronic Phone Book",
JOptionPane.WARNING_MESSAGE);
}
Please help. I dont understand why in eclipse work and why on exported jar file not working :((
With the help of user "MadProgrammer" i was able to figure and solve my problem.
Also with this i learned how to use a very importand JAVA command console for running my jar files, where is showing everyting in execution of the program. Soo the command that i used to find the problems is this
java -jar myExecutableNameFile.jar
And my problem was this:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at cnbi.AgendaTelefon.Java.GUI.PaginaAdd.<init>(PaginaAdd.java:388)
at cnbi.AgendaTelefon.Java.GUI.PaginaPrincipala$9.actionPerformed(PaginaPrincipala.java:371)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
My solution was to remove a duplicat image (that has similar name with the current menu image who was calling that jframe to be visible). After i deleted the code and inserted the correct one with new image path... everything works perfect now.
I want to thanks once again to you "MadProgrammer" because you saved me. I was searching to solve this for 5 hours until you came :)
Problem:
I am trying to write a barebones android application that just shows your advertising ID in a textview. My code compiles fine but when I run it my textview remains unchanged (it just remains as "New Text").
This is a picture of the screen I'm getting on both my AVD and Actual Device
My Code:
I have already imported the google play services SDK and am using this following code within the onCreate method which is within the MainActivity class.
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//The textview I am trying to change
uniqueID = (TextView) findViewById(R.id.special);
// declarations for included ad plugin
adtechView = (AdtechBannerView) findViewById(R.id.ad_container);
adtechView.getAdConfiguration();
Context mContext = MainActivity.this.getApplicationContext();
try {
//This should be getting the advertising ID
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
String AdId = adInfo.getId();
//This should change the textview "uniqueID" to the Ad ID
uniqueID.setText("Your ID is " + AdId);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
What I've tried:
I have looked into the problem through some of related questions. multiple sources say that the code might not work due to not having access to google play services.
I have tried running the code both on my AVD which does not have google play services and on my actual device which does. Both end up with the same result. (textview remains unchanged)
I have written this code based on this website: https://www.safaribooksonline.com/blog/2014/01/16/advertising-id-android-kitkat/
which provides a tutorial for retrieving the Ad-ID.
I have also used this stack overflow as guide, but I am not face with the same issue his code was facing:
AdvertisingIdClient getAdvertisingIdInfo hangs forever
What am I doing wrong? Thanks so much in advance!
You can't get the Advertiser ID from the main thread. https://www.safaribooksonline.com/blog/2014/01/16/advertising-id-android-kitkat/
From the code above, it appears that this is taking place on the main thread. I'd recommend using an AsyncTask. Put the advertising ID in the doInBackground implementation. Since you can only modify UI on the main thread, set the text of the TextView in the onPostExecute implementation.
I am wondering if (and if so, how) it is possible to create new, empty text file(s) in the app directory when the app first installs. Until now I've always done a:
File cart = new File(this.getFilesDir(), "cart.txt");
if(cart.exists() == false) {
try {
cart.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
But this seems a bit impractical if I need to make about 10 empty text files and it needs to check all those 10 before it starts every time.
I was thinking maybe somewhere in the Manifest but I haven't found any online solutions.
i am creating an application for android in eclipse.
i have a chat application in which user's contact's images are downloaded in sdcard and are put in a HashMap (url, localAddress), when i want to load contact list, for any contacts I use a function to find address of contacts' pictures on sdcard, three different state may occur
1- image found on sdcard then return path.
2- image don't download before and HashMap return null, then download it.
3- HashMap return a path but user deleted image from sdcard then remove key from Hashmap and download again.
my code:
public static String findFile(Context ctx, String url, String type)
{
try
{
String value = globalVars.addresses.get(url);
if(value != null)
{
File ff = new File(value);
if(ff.exists())
return value;
globalVars.addresses.remove(url);
}
globalVars.enqueueJob(ctx, new globalVars.downloadJob(url, url, type));
return null;
}
catch(Exception ex)
{
Log.e("Find File", "Start");
Log.e("Find File", ex.toString());
ex.printStackTrace();
return null;
}
}
but when i delete an image it download more and more .
function enqueueJob :
public static void enqueueJob(Context context, downloadJob dj)
{
if(inQueue.get(dj.getAddress())!= null && inQueue.get(dj.getAddress())== true)
return;
downloads.add(dj);
inQueue.put(dj.address, true);
FileUtils.doDownload(context);
}
It work's fine for pictures don't download yet and pictures that download and don't delete yet.
Your title is confusing as it indicates you suspect the File.exists as the problem. Looking at your code, the fact that deleted images are added to download queue means File.exists works fine at least the first time. Otherwise, you would not even add it to the queue. Now the question is what happens when it is added to queue and downloaded. Check your code to make sure that it added back to the map properly. In your code, something should be added to the download queue only under two conditions: one if nothing in the map and the other is whatever in the map is deleted. So either it is not added back properly or may be a race condition where your File.exists is happening before the download is completed fully and you are adding it back to the queue again.
Good luck.