|
By:
It's a problem with the clacker.
Switch off, wait 10 seconds and then go to the pub. HTH |
|
By:
I was waiting on a funny answer
![]() I know Chit Chat is not a good place to ask such things but I'm hoping just one Chit Chatter can help. Hoping someone can point me in the direction of a noobs forum where I can ask such questions. |
|
By:
I was going well until I got past "trying"
![]() |
|
By:
Is it because dateTime is local to getDateTime().
|
|
By:
It's only took me 3 long years to get to making my own programs and I've nothing (yet) on the Play Store. Never give up Saddo, you will get there one day!
When you ask such questions on Stack Overflow, you always get some condescending expert that find a fault in your question. If I knew the bloody answer I wouldn't be asking the question. I'm scared to ask over there TBH as my first and only question was downvoted for being a noob question. I'd love to find a simple forum where you can ask such questions. Despite searching I've yet to find a decent site. Google Groups is about the best I could find. |
|
By:
Thanks Charlie, I thought because I made the method public it returned dateTime as a String? I've tried passing in a String as part of the method but I'm unsure how to return an actual value. Any help as to completing the code?
|
|
By:
Ovalman it's been a few years since I did any programming and never on Android. Even though getDateTime is public I don't think it's variables are public (I may be wrong though!).
What happens if you put Public String dateTime above your first line ( getDateTime() ) and remove String from String dateTime = df.format(c.getTime()); |
|
By:
I'm not sure I entirely understand your post Charlie but I've joined Androidforums who have a small but active programming section. I've asked over there.
I know it's not something to complicated for my answer. OOP does my head in. I grew up in the 80's where Spaghetti coding was all the rage. I'm much more used to BASIC than I am to Java but I need to learn Java as my programming ideas suit a mobile platform. As I said, I've only been trying for 3 years! I am getting my head around things now and can make apps that actually work. |
|
By:
I do all my android programming on iOS you should move there too. Its much easier.
|
|
By:
Ok here is what I am thinking. I can do some java but not android, and dont know if there is a big difference. I just checked how java stores date and time. In that class, there is a separate method that converts the date to a string! So its not a given that the date is stored as a string.
In your program, df.format(c.getTime()); is returning a string, are you sure about that? When you declare a variable, it contains null(I think :)). So if your method is returning null, it means the line df.format(c.getTime()); is not putting any value in the variable String dateTime. Why don't you try initialising String dateTime with a value, ex. "hello". Then if your method, is returning "hello", you at least know df.format(c.getTime()); ain't doing shlt. I really suspect the line df.format(c.getTime()); to be the main issue here. At least show us what the method format() is doing. |
|
By:
I'm making a toast of the string which is a pop up to tell me what the variable is. Toast.makeText(this, dateTime, Toast.LENGTH_SHORT).show();
dateTime is my String. I'm returning the String in the next line: return dateTime; I think I've set up the method wrong. I tried it this way and still get null: public String getDateTime(String dt) { Calendar c = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); String dateTime = df.format(c.getTime()); // dateTime has current date/time Toast.makeText(this, dateTime, Toast.LENGTH_SHORT).show(); // The variable dateTime is a String but the method returns null dt=dateTime; return dt; } |
|
By:
You didn't answer this: In your program, df.format(c.getTime()); is returning a string, are you sure about that?
You can easily put values into the vriables you are returning to see exactly which line is giving the error. Did you understand that part? Or should i explain it again? |
|
By:
Yes, I'm running it in debugging mode and dateTime="30-01-2017 23:42:52"
I changed dateTime to "test" and still getting a null value. Passing the value from my method or calling the method seems to be the problem. |
|
By:
Could this be the problem?
getDateTime(); returns a value, namely dateTime. But when you call the method in your program, it does return the value. But where should it return the value to? it does return, but there is no variable to put the value into. Try String oval = getDateTime(); in the first line Now oval should have the date in it. |
|
By:
Sorry for my horrible english in the second line. Butts galore.
|
|
By:
Basically when you 'get' some value, you have to put it into a variable to use it later.
When you get a pack of milk from the market, you need a bag(or hands) to put it in and bring home. In the first line of your code, you are saying you are getting the packet of milk, but you are leaving it at the counter and wondering where the milk is when you reach home. You need to put the milk in the bag(variable) and bring it home. Only then can you use the milk. |
|
By:
I might have solved it and you were correct.
String dateTime = df.format(c.getTime()).toString(); Toast was allowing dateTime as a local String hence it showing as a Toast it wasn't being passed as a String back to my method call. I added .toString(); and I think it has cured the problem. When I ran it in debugging the variable was inserted into my database according to debugging. Need to write some code to get the data back out of the database to make sure. Sqlite is a bugger for Android unless your device is rooted so you can examine the database directly to check for values. |
|
By:
Yes I was talking about the toString() method.
But is your first line of code now working? You need to put the result of that line in some variabe. Otherwise it doesn't make sense. It gets the value and then has nowhere to put it in. |
|
By:
helper.insertIntoPaid(strId, amountpaid, dateTime, "Notes Paid", "Spare 1", "Spare 2", "Spare 3"); //insert into paid table
But it's a public variable and things should be private whenever possible but the whole code I'm using is inside a button so nothing happens until the button is pressed. I sorted the notes column while I was checking elsewhere for this solution. That updates my paid table in my database. The spares are just that in case I need them for anything in future, that's why I reference them directly as strings. Another wee bit done, as I said it's only been 3 bloody years! |
|
By:
I get started next month on android prog.
|
|
By:
I've done Python and C# courses, both of which are easier than android but it's Android I want to develope for.
I tried many Youtube and online courses but it wasn't until I done a couple of free courses on Udacity that things started to make sense. I still struggle with implementing Object Orientated Programming, it's totally alien to what I grew up with. I'm guessing your doing a computer science degree? My son is 2nd year of Computer games programming at Coleraine University, I guess it was him that inspired me to try and learn it again. I've a few apps including this one that I think I could monetise. You've been a great help Detraveller and thanks also Charlie for the response. I'm still waiting on someone to answer this problem on that Android forum I joined so Chit Chat comes up trumps again. |
|
By:
what you need is more negative integers. get a pepper pot and sprinkle them in.
|
|
By:
I am studying maths at University. Actuarial Science to be exact.
|
|
By:
Crikey , never thought I would see code on here and a programming question , as an IT veteran of 35 years and a grizzled old programmer of the 1980's , it is a joy to see.
![]() |
|
By:
Ovalman - if you are from a BASIC programming background and now you want to program for Android then maybe Bassic4Android is the "easiest" option for you https://www.b4x.com/
|
|
By:
*Basic4Android
|
|
By:
Thanks for the replies guys.
Smar Tarse, I've been through all those programs, Google's Appinventor will have you creating apps in minutes but it's not what I need. I've took many courses but only when I done this course did it all make sense. It brings everything straight down to basics: https://www.udacity.com/course/android-development-for-beginners--ud837 There's a few courses more advanced but getting that under my belt made things so much easier. I can thouroughly recommend it. If I'd have took that at the start instead of following coders on Youtube then I wouldn't have struggled so much. I'd love to find a decent forum where I could ask questions like above without getting flamed because the question has been asked before. Don't they think I already tried searching for the problem? |
|
By:
I'm astonished you got an answer to this on here tbh! You can always try google the question and type forum after it you just have to know how to manipulate the search terms.
|
|
By:
That's the problem. Most of the time it is about Googling and adapting other peoples code but sometimes you just get stuck and can't see the problem if it stares you straight in the face. I was getting nowhere on Facebook and I didn't want to ask on Stack Overflow so I though Chit Chat may help or at least point me to help. Detraveller pointed me in the right direction even if he couldn't see it directly himself.
Chit Chat wins the day. |