last day (19 days later) » 

4:14 PM
0
Q: Weird catlog provides no explanation

Bradly SpicerRecently started getting a rather odd Catlog which doesn't describe what's going wrong very well. I have it posted here: http://pastie.org/9415113 Line 55: DebugCarTxt = (EditText) findViewById(R.id.DebugCar); // you should instantiate 'DatabaseHandler' here Database...

 
Thanks @Eran I've updated my OP because the Android Studio IDE doesn't provide any distinct errors.
 
FYI its logcat not catlog, although I like the sound of that
 
@RichardTingle my bad.
 
As far as I can see cars is null. Why will be found within db.getCurrentCar();
 
@RichardTingle Could this be because my database is empty, therefore it cannot grab anything and returns null?
 
4:14 PM
From your edit; I'm assuming cursor.moveToFirst() returns false, which would lead to the whole method returning null. I suggest stepping through the code in a debugger
 
@RichardTingle Thanks
@RichardTingle would you be willing to have a discussion about this?
 
Absolutely, however, I don't have sql experience so if the problem lies there I may not be your man
 
 
2 hours later…
6:30 PM
Hi Richard
 
Are you free to help in about 30 minutes? sorry for dragging you like this! First project and I have a tightish deadline :p
 
Sure, as I say though I don't know sql. If its a pure Java problem I should be able to help you though
 
Thank you very much, I know SQL a fair bit :)
 
Cool, together we should get there then
 
6:42 PM
:) thanks!
 
7:29 PM
Hey dude
I'm here :)
 
How are you?
 
Not bad not bad, working on my side android project but I've got a few minutes to talk if you need assistance. You?
 
I'm struggling with this app :P
basically i've been offered this chance of training + a job but I need to do a task they've set which I've calculated as near impossible xD
They want an image stored in a SQLite database and then put into an ImageView
 
Tell me about it. Have you run it through in a debugger
 
7:34 PM
and I guess I've been learning along the way
Not quite sure how to debug ;P
 
Cool, what IDE are you using?
 
Android Studiop
I used to use Eclipse, but I thought this was the future :p
 
Hmm, I have that on my machine but its my third favourite IDE so it will take me a second to get up to speed. One seconf
 
Okay :) What's your #1? :P
 
Netbeans for general java, eclipse for android. May move over to android studio once its stable release
 
7:38 PM
ahh :)
 
Ok, this works very similarly to eclipse. What you want to do is place a break point a little before the nullPointerException line. You do this by clicking in the margin (a red circle will appear). Then you go to run --> debug 'app'. When your program gets to the break point the code will stop excecuting and you can see what each variable currently is (which are null) and step through the code
(the margin next to the code)
 
should I do this in MainActivity or DatabaseHandler?
Where the method is or where it's being called? :P
 
Arguably it doesn't matter. The debugger will stop on the line where you put the break point but you can then step "inside" the method. Basically the break point is just to get us to the right general area then we can move forward in time
 
Ohhh okay
So I've overdone it ? :P
 
A tad ;p
 
7:45 PM
http://puu.sh/ao4qK/7ac4f3d7ec.png

So this is okay?
 
Probably, but I would put a break point on sqLightDataBase=....
sqLightDataBase db=....
 
I'l do that whole top part too
 
cool, too many isn't really a problem
 
:) So now I run in debug mode?
 
Go for it
 
7:49 PM
Hmmm.... clicked the Debug button ... nothing happens
aha there we go
asking for Emulator
Ok :) so it's given me a new box at the bottom
 
I believe that allows you to look at object trees. Does code excecution appear to have stopped
 
I guess I step Into the method? :)
 
yep, you can not move forward through the code. If its anything like eclipse you can look at what variables currently are by hovering your mouse over them
 
And specifically the SQL query is the suspected culprit :p
 
Definately have a look at that
 
7:54 PM
Is this saying there's no Database o.o

http://puu.sh/ao5aL/b65d2665a8.png
 
That image appears not to be available
Also; that sounds like it may be the problem!
 
damn it puush!
It's opened SQLiteOpenHelper.java :P
wait! It is connecting
in String sql it says Database = and has some values
 
does the db variable look correct?
 
it appears so?
 
Hm, in the doc, what does it say about the method cursor.moveToFirst() specifically conditions under which it could return null
Ok, the docs says "This method will return false if the cursor is empty."
 
8:03 PM
public abstract boolean moveToFirst ()

Added in API level 1
Move the cursor to the first row.

This method will return false if the cursor is empty.

Returns
whether the move succeeded.
so yea, true or false
 
You're the sql man, what does an empty cursor mean?
 
cursor isn't sql to me xD I know SQL from PhpMyAdmin etc :P so I know SQL queries etc
I thought cursor was Android based
 
It is, but its database orientated "This interface provides random read-write access to the result set returned by a database query.". Suggests to me a problem with your query
 
I've just thought...
my cursor is getting 4 strings
I'm only querying the ID and Image
I've just added the Address and Postcode in the SQL query
No error!
Hooray :)
 
Awesome. I'm not sure how helpful I've been but I'm glad that its resolved!
 
8:11 PM
You've been an absolute star! I have one last hurdle and then this app is completed :)
thanks so so so much Richard :)
 
Mind if I hold onto you here incase I break it again? :P You got my momentum back
 
No problem
 
So, now. In theory pastie.org/9415703 the EditText will be the output from the Database!
(cross fingers)
 
I can't see anywhere in the code where you actually set DebugCarTxt etc to have a string
 
8:16 PM
Wait, all I've done is define it? :(
 
btw, while i'm looking at this code. The java naming convention is class names in UpperCamelCase and variable names in lowerCamelCase. So DebugCarTxt should be debugCarTxt
 
ty :)
 
Indeed, you'll need to call setText(theTextYouWant) on those objects
 
so, DebugCar = SetText(String rows= "id : "+ cars.get_id()+ " address : "+cars.get_address() + "postcode : "+cars.get_postcode()+" image : "+cars.get_image());
 
No, something along the lines of debugCarTxt.setText(cars.someMethodToGetText)
correction debugCarTxt.setText(cars.someMethodToGetText());
 
8:20 PM
And that's inside the MainActivity.java?
 
Its all underneath the code you postred in pastie.org/9415703
 
However. I suggest you seperate out the database testing and the editText testing. Try to just put "hello world" in there first. Then try to put the database output in there
 
GENIUS!
Also, I liked the use of hello world :p
debugCarTxt.setText("hello world!");
 
Assuming getImage() returns a string (which seems suprising) then that should work
 
8:23 PM
it's supposed to return a string because I was told it needs to be a byte[]
which I convert
 
Got to be "hello world", anything else is just heracy
 
:P
Am I right with that theory btw? :P Of converting the string into a BitmapFactory where it draws the image?
 
To be honest it suprises me. Of course everything arrives in Bytes but I'd expect those to fairly quickly become an image. Having an image expressed as a String does seem a little odd
Nice!
 
Oh... am I doing this wrong then? haha
 
It suprises me, doesn't mean you're wrong.
 
8:29 PM
Ahh... I'd rather learn to proper way if I'm honest :P
 
Looking at BitmapFactory it looks like it wants to take a byte[] rather than a string
 
Ahh... is this going to be difficult to convert?
Because I thought I put the string into the Byte xD
I also actually need to convert an image into Bytes for testing purposes
grabbing it from the Database :) :) :)
 
Cool, so you're definately getting something. Is that the image? It looks like hexidecimal for the number 41151
 
It's a random string I made :p
Also... did you work that out in your head?
 
Ah, teaches me for seeing patterns where there are none
 
8:34 PM
:P
 
It's a very very unique skill I guess ;)
haha! you got me!
So! now I need to delete all my work! and make it bytes[] :'(
 
Not neccisarrily
 
Hmm? :P
 
Assuming you know how your String has encoded the bytes you can convert back using Byte.parse(someString). But you need to presplit the String into indivual byte sized portions. If your string going to be 01101101; if so converting back should be easy
 
8:38 PM
Oh.. I don't :P I haven't even technically made something that makes it bytes...
 
Easy but inefficient of course. The transfer size will be orders of magnitude larger encoding it as the "characters" '0' and '1'. If you can easily send byte[] from your database that is going to be better. But that is again wandering outside my area of expertise
 
ahh crap :(
Would you be able to help me with the string method? I've built it from here I might as well continue
 
Sure, give me a sample of what you are actually recieving as your "image as a string" and we can see where we go from there
 
I suppose I should actually make a real converted image?
not just a random string I made
Or do you want the image I'm going to convert? :p
 
Really I want to see if you do indeed revieve 01101101 or something else. My fear is that Byte is just like int and long. Except while int is 4 bytes long byte is 1 byte long, So byte b=5; System.out.println(b); gives an output of 5, not 11. And if it'd encoded like that 55 and 5,5 become indistinguishable
You can of course put a deliminator beween each value in the string but it is going to be slow converting that back from a string to an image
 
8:48 PM
As long as it works :P I'm happy
this is only a demo app, once I've got the job I get training ^.^
and I can apply myself properly not in this 6 hours a day stressed state
 
Cool, then try to convert your image to a string and lets see what you get
 
So I need to find a way of converting it :p
So, I've placed those images into a folder called images
 
Are the images being packaged with the app? If so there is a wildly easier way to do this
 
The requirement is to have them in a database
but they're not currently in a database as a bytearray
So I'm trying to convert images I have
to put in there
 
You may find this very interesting; stackoverflow.com/a/9768973/2187042 It explains encoding and decoding a bitmap as a string
 
9:00 PM
So what that'l do is take in the image and then return the byte[] decodedByte = Base64.decode(input, 0);
return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
 
Yep, you should be able to store that String in your database without ever really caring about how its encoded because Base64 deals with the whole thing. It should even be relatively efficient like that
 
I'l try and do this on my own :P if I really struggle I'l poke you ;P But I'l try my best on my own :)
 
Cool, be aware where I am night is swiftly falling so I'll be gone in an hour or so
 
It's 22:05 here :P
Is there any way I can recontact you? :) You seem like an awesome person
 
I'll keep this discussion open and check in on it periodically
 
9:07 PM
=] Thanks dude
With that example you gave me
do I call encodetobase64(PATHOFBITMAP); ?
sorry, decode
Wait, I am meant to be encoding it!
:P
 
No you give it the bitMap itself. BitmapFactory can be used to load it into java
 
ohhh so BitmapFactory finds the file, converts it to a string then I encode it with the encodeTobase64
then the return goes into whatever my drawing part will be?
 
9:23 PM
HardDrive --(BitmapFactor)-->Bitmap--(encodeTobase64)--> String --> Put in dataBase.
DataBase --(your existing code)-->String--(decodeBase64)-->Bitmap-->use as you see fit
*BitmapFactory
 
Gonna write that on my project :)
Should I put all this in another in another class? :P
 
Its always good to roll things up into a discrete class, then you never need to worry about how it works again, just that it does
 
awesome :)
It appears bitmapfactory is rather small
No need for a method?
 
The existing class bitmapfactory. or your use of bitmapfactory?
 
trying to use it, having a look atm
I made a class called EncodeImage.java
and I have one called ByteConvert.java
which was meant to have the bitmapfactory in... but it looks tiny
 
9:37 PM
Assuming you mean your use, then yes, its pointless to encapsulate a single method call within its own method. It can just go "raw" in a higher method
Ah yes, a 2 line method is too small a method
(usually)
 
So is the BitmapFactory normally only 2 lines long?
ImageView image = (ImageView) findViewById(R.id.test_image);
Bitmap bMap = BitmapFactory.decodeFile("/sdcard/test2.png");
image.setImageBitmap(bMap);
 
All depends how you're using it. I notice you're setting the ImageView's image from the bitmap you got from the hard drive rather than the database. Is this currently your encoding step? If so it shouldn't include an ImageView at all
 
The whole thing should be within a high level method (one that is called to perform the entire File of HardDrive-->String step). You can't have method calls just hanging around in the class like that. The method could also probably be static (i.e can be used without an object, the same way BitmapFactory.decodeFile() is used without creating a BitmapFactory object)
 
9:56 PM
public class ByteConvert{

public static Bitmap imageTobMap() {
ImageView image = (ImageView) findViewById(R.id.test_image);
Bitmap bMap = BitmapFactory.decodeFile("/images/car1.png");
image.setImageBitmap(bMap);

return bMap;
}

}
something like that?
 
yes but the ImageView imagestuff is pointless and can be removed (note what the method returns). I also note that it's only half way there, it gets the bitmap but you still need to convert it to a string. Remember this is your initial conversion, which you will do only once. This code won't run on your end users machine (the other side will, that brings the string back to being an image).
 
Ahh that makes sense, as the only place I am actually defining images etc is the mainactivity
Should have guessed :P
public static Bitmap imageTobMap() {
Bitmap bMap = BitmapFactory.decodeFile("/images/car1.png");
String bMapString = bMap.toString();

return bMapString;
}

won't work ^.^;;
 
By doesn't work do you mean gives an exception (if so what is it) or gives an incorrect result (which is very likely toString() gives a human friendly representation of an object. You want encodeTobase64()
 
Incompatible Types :P but I need to encodeTobase64() first? :P
 
Ah, I note you still have your return type as Bitmap not String
 
10:09 PM
Oh duhh!
 
You still need to change for encodeTobase64() as well. You'll probably get "width 100 height 200" or just "Bitmap#1242334" at present
 
see, that looks fine but yes, it does need to be converted with my encodeTobase64()
 
Incidently to give some background 'toString()' is a method every object has. It usually doesn't give anything particularly useful and is usually used for debugging
 
ohh haha
public static String imageTobMap() {
Bitmap bMap = BitmapFactory.decodeFile("/images/car1.png");
//String bMapString = bMap.toString();

return encodeTobase64(bMap);
}
 
yep, that should do it. Then put that string (which should be huge) in your data base and you're done
 
10:14 PM
Okay, so now back to MyActivity!
Sorry Richard! am I keeping you up?
 
No, I'm winding down but I'm still here
 
Okay :)
Sorry, having a slow moment again
 
Whats the issue?
 
How do I call a method from another class again? :P
 
If its static then its ClassName.methodName()
If its an instance method then you need an object to call the method on
 
10:27 PM
Ahh! and then I use that inside my createCar method?
public void createCar(Car car) {
SQLiteDatabase db = getWritableDatabase();

ContentValues values = new ContentValues();

values.put(KEY_ADDRESS, car.get_address());
values.put(KEY_POSTCODE, car.get_postcode());
values.put(KEY_IMAGE, car.get_image());

db.insert(TABLE_CARS, null, values);
db.close();
}
so I would use that but I would create a new car with the ByteConvert.imageTobMap();
 
Indeed, you can call any static method from anywhere like this (assuming the method is public)
 
db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(),cars.get_image()));
Could be

db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(),ByteConvert.imageTobMap()));
 
Yeah, that looks good
 
So now, if I run the script then it should add that to the DB? :)
 
I believe so, give it a go! (although it might be worth printing out the String value you get first just to make sure it looks right
 
10:35 PM
I've just opened up the database xD
having App crashes again.
f my life
 
Whats the exception?
 
trying to get logcat to work
but it's not :|
 
Where you running this as an app, or as a normal Java application. Logcat is android only, normal java programs send the exception to the console
 
as an app
 
hmm, and your logcat has worked previously? odd
 
10:44 PM
yea
Going to close all emulators
 
If in doubt restart, I know its a cliche but it works. Btw do you have a real android phone? Working with emulators is a nightmare (not that I'd suggest setting that up now, just something to think about later)
 
Not at the moment, it recently burnt out haha
if I get this job I'l get a few
could it be because they're pngs not jpegs xD
they need to be bitmaps?
 
All the top bit isn't important, The line that matters is: com.example.brad.myapplication.ByteConvert.encodeTobase64(ByteConvert.java:19). Something on that line is null
 
Yea is that because it's imagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
so it wants to be a JPEG? as a Bitmap compression? But it's a png?
 
Ah yes, and its returning null because it can't be compressed. Try removing .JPEG from the Bitmap.CompressFormat then just put the . in, it will give you a list of possibilties. PNG will probably be one of them
I've just had a look and it is need. 90% of the time I'm looking to see whats available on autocomplete; its so very useful
 
10:55 PM
:P I think I put in "Png"
not "PNG" xD
which is why I asked after I got the error and reverted to JPEG
Attempt 2!
More errors :(
Fresh restart :)
 
What are the errors? if you're getting errors then restarting is unlikely to help
 
http://puu.sh/aoksz/18e814affd.png

and I'm just getting the logcat now :P
 
Same exception, i think its time to step through in debugger again. See exactly where the null turns up
 
I am :)
wait
db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(), ByteConvert.imageTobMap()));
I'm not giving it anything to convert :P
Or not..
Richard, you around? :) I'm trying to debug this class
 
11:13 PM
I'm afraid I'm just on my way to bed, If you've got a quick question I can answer but then I must depart
 
No worries Richard, I'l stop pestering you :) have a good sleep! Thanks for everything :)
 
No problems, any questions leave them here and I'll try to answer in the morning. Goodluck and goodnight
 
Thanks :)

Well, I'm debugging. And it's gotten caught on ByteConvert.imageTobMap();

as seen here: http://puu.sh/aom6O/854c7e8bc5.png
However, the source looks correct to me: http://puu.sh/aomb3/fe23575a61.png

Have a good night :)
 
11:34 PM
As a last bit of advice, i note that BitmapFactory.decodeFile will "If the specified file name is null, or cannot be decoded into a bitmap, the function returns null." Incidentally that's a horrifying decision; returning null is almost always the wrong thing to do. Most java code isn't written like that and don't let it put you off java.

my suggestion would be to make sure the file really is where you think it is
In particular your emulator can't access your computers hard drive only it's own emulated memory
(Which is technically on the hard drive but you know what I mean)
 

  last day (19 days later) »