I have finally sat myself down and gone over Google's tutorials for building Views in Eclipse and I'm trying the Grid View. I have edited what I've needed to edit, and copied and pasted what the Android Developer site said to paste. I figured out what I need to do for most of the errors that I had, mainly having to rename my pictures from the sample_thumbs to my own image names, but I am still getting an error at one spot, which gets me because I copied and pasted it, but I have a feeling that there is something I'm supposed to edit myself here but I don't know exactly what it is
Toast.makeText(HelloGridView.this, "" + position, toast.LENGTH_SHORT).show();
HelloGridView cannot be resolved to a type. that's the error that I'm given.
Can anyone help me here? Thanks in advance to any assistance, I spent a little while narrowing down about 25 errors to this last one and don't know what is going on here.
I actually figured out this problem. Its is a quite quirky little error. It was actually a problem with the labeling of the Activity
public class HelloGridViewActivity extends Activity {
--should be
public class HelloGridView extends Activity {
but it is not, so you have to change all other instances of HelloGridView to HelloGridViewActivity
This causes a problem with the later code that is simply (HelloGridView.this, ""
.....it is referencing the Activity HelloGridView and gets mixed up because the public class is HelloGridView, so if at any time you need to use methods of the class HelloGridView, and Eclipse labels your class HelloGridViewActivity, then it will not work.
lemonoid said:
I actually figured out this problem. Its is a quite quirky little error. It was actually a problem with the labeling of the Activity
public class HelloGridViewActivity extends Activity {
--should be
public class HelloGridView extends Activity {
but it is not, so you have to change all other instances of HelloGridView to HelloGridViewActivity
This causes a problem with the later code that is simply (HelloGridView.this, ""
.....it is referencing the Activity HelloGridView and gets mixed up because the public class is HelloGridView, so if at any time you need to use methods of the class HelloGridView, and Eclipse labels your class HelloGridViewActivity, then it will not work.
Click to expand...
Click to collapse
You also need to import Toast.
Code:
import android.widget.Toast
Your code doesn't have to exactly match the tutorial. If you intend on using it in your own app, HelloGridView should be the name of the class that displays your GridView. Thusly, any line of code that references the class should be the name of the class as well, such as the Toast.
Related
Hi I want to make an application using location, I found this tutorial
http://msdn.microsoft.com/en-us/library/dd938890.aspx#RetrievingLocationInformationthroughGPS
which looks very helpful but because I am new to visual studio I am having some problems.
1) is the article it says "This article includes complete sample code." but I cant find a download for all the code.
2) he only mentions referencing Microsoft.WindowsMobile.Samples.Location.dll which I have done but the class LatLong is still unknown
3) I made a sample program without the LatLong class just to experiment I get the following error on my device
"Microsoft.WindowsMobile.Samples.Location, Version=1.0.3448.25673, Culture=neutral, PublicKeyToken=null, or one of its dependencies, was not found
any idea what this means?
4) Could all my problems be because I am using visual studio 2005 and not 2008? I found a code project that looked really helpful but when trying to open it it says that it cant because it is from a newer version of the software, anything that can be done?
5) I find MSDN confusing for finding out what to reference to add a class for example this is the page for the LatLong class http://msdn.microsoft.com/en-us/library/cc514548.aspx
with the java online info the first thing you always see is where the class is found but it seems to be missing for this class. Other basig classes appear similar to java.
below is my sample code its basically taken from the article but I have commented out the references to LatLong and put in checks instead
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Samples.Location;
namespace DeviceApplication3
{
public partial class Form1 : Form
{
private Gps gps;
int count = 0;
public Form1()
{
InitializeComponent();
gps = new Gps();
gps.Open();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = (getGpsString());
}
private string getGpsString()
{
GpsPosition position = gps.GetPosition();
/*LatLong location = new LatLong();
if (position.LatitudeValid)
location.Latitude = position.Latitude;
if (position.LongitudeValid)
location.Longitude = position.Longitude;
if (position.HeadingValid)
location.Heading = position.Heading;*/
StringBuilder sb = new StringBuilder();
sb.Append("\n");
sb.Append("Latitude = ");
if (position.LatitudeValid)
{
sb.Append(position.Latitude.ToString() + "\n");
}
else
{
sb.Append("Not found yet\n");
}
sb.Append("Longitude = ");
if (position.LongitudeValid)
{
sb.Append(position.Longitude.ToString() + "\n");
}
else
{
sb.Append("Not found yet\n");
}
sb.Append("Heading = ");
if (position.HeadingValid)
{
sb.Append(position.Heading.ToString() + "\n");
}
else
{
sb.Append("Not found yet\n");
}
return sb.ToString();
}
}
}
Microsoft.WindowsMobile.Samples.Location.dll
is this file located in bin\debug and or \bin\release
?
and does it only give runtime errors or also compile time ?
no it compiles fine, can you see anything wrong with my code? The weird thing is the form comes up using the emulator but not on the device. Could it be because I have a custom rom that seems to have compact framework 3.5? I would assume it would be back compatible?
How have you deployed it to the device? Have you copied the .exe and the Location.dll?
one thing you could also test was if you could disable the stuff in the gps
and just run a program without it to verify that it's not missing net3.5's fault
heliosdev said:
How have you deployed it to the device? Have you copied the .exe and the Location.dll?
Click to expand...
Click to collapse
Hi thanks for this I didnt copy over the dll I'm very silly.
So what do you guys think about loading projects ment for vs 2008 in 2005 is this impossible ? or can i convert them somehow?
sure it's only the project and solution files which differ
add the cs files manualy and it should work fine
Use the same name to create the new project in vs2005 to have the same namespace.
You'll have to do some manual changes if the code uses c#3.0 .net 3.5 features.
Thanks guys your awesome,
very random and off topic but since your programming kings ill ask anyway,
I think I want to eventually work in the gaming industry, I'm close(3months) to finishing my MSc CompSci conversion course and I am looking for jobs, its quite aparent that most games companys don't want unexperienced people so do you guys have any ideas of places to apply for that will give the the necessary experience? btw I have no taught experience with C++ which I think is my biggest dissadvantage, I do know C and java quite well though and as you can tell just starting to play with C#.
your help is always appreciated.
well, continue with general programming (object oriented programming, ui development, database, network,...). There are so many different fields in software development!
For example take a look at the chapters of the books in the game programming gems series to see what (not only) gaming companies are working on. In general for beginning there is a lot of information online where you'll find tons of tutorials.
Try to get a profound base in programming.
Starting with your gps application, develop a gui, save/load the positions (database), visualize the points...
heliosdev said:
well, continue with general programming (object oriented programming, ui development, database, network,...). There are so many different fields in software development!
For example take a look at the chapters of the books in the game programming gems series to see what (not only) gaming companies are working on. In general for beginning there is a lot of information online where you'll find tons of tutorials.
Try to get a profound base in programming.
Starting with your gps application, develop a gui, save/load the positions (database), visualize the points...
Click to expand...
Click to collapse
Hi sorry for the late reply I upgraded to windows 7 last night to try and improve my rubbish laptop, seems to be a bit better btw,
anyway just want to say thanks for the advice. also my app will use google maps yahoo zonetag and windows live earth (or bing maps if thats what there calling it now) I think for some of thoes services I will need to pay to realease my app to the public even if its free but what about testers would I be able to give it to say 10 people?
Hi there. I need some help
I'm trying to make a radio app for HTC Desire but as you may know, there's no official API for that. So it's time for some hacking. By decompiling the FM Radio app and the framework.odex into .smali files I was able to find the path to a class that is used to control the FM tuner It's a system service. getSystemService with a string I've discovered returns an instance of the FmReceiver class.
So let's say FM_SERVICE is a string containing the service name.
Let's say FM_RECEIVER_PATH contains the path to the FmReceiver class (like com.something.FmReceiver)
By using the .slimi files I was able to see the methods inside the FmReceiver class. So I made a new abstract class and put all the methods I saw in the original FmReceiver.slimi file as abstract methods (because there's no way I can reconstruct their bodies). I renamed this file FmReceiver.java and put it in a package FM_RECEIVER_PATH into my Eclipse project.
So in the end I have a FmReceiver class in my project which does nothing (because all its methods are abstract) and a FmReceiver class which is on the device, in its framework.odex which has the same methods as my FmReceiver class except that they really have code inside and can do useful stuff.
To illustrate the things I've done so far:
Code:
Class<?> receiver_Class = Class.forName(FM_RECEIVER_PATH);
Object obj = getSystemService(FM_SERVICE);
Object instance = receiver_Class.cast(obj);
FmReceiver receiver = (FmReceiver) instance;
receiver_Class.isInstance(obj); //returns true
instance.getClass().getName().equals(FmReceiver.getClass().getName()); //returns true
I'm sure that the variable instance has the correct instance of the device's FmReceiver class. But can I cast instance to the class FmReceiver I've made like that? That code doesn't raise any errors but the functions are too complicated to track them to see whether they work.
So my question is - is this correct? Can I make such a cast to an abstract class and expect it to work properly afterward
Hah, you are using similar technique to mine in Google Maps mod You don't have to use Java reflection API, you could use your stub class as usual and at runtime the framework one will be used
Really?!? I haven't thought of that I'll try it
Oh yeah, oh yeah, oh yeah!!! It worked!!! Wow. Thank you man! I've been struggling with that for so long Actually it would have worked the way I did it as well, but now I discovered that I had an error in one of the methods in the abstract class Anyway I was so glad when that listener returned a value Cheers
Hey guys, I know this thread is probably better suited for the development thread, but I am not allowed to post there, so here goes:
I am working on improving the notepad app that is created through the notepad tutorial provided for android development, and at the moment I am trying to make a preferences page that allows me to enter a number, hit confirm, and the app will use that number to change the font. My approach so far has been to pass a startActivityForResult call, which returns a number, then in my onActivityResult I check for that number which should be returned. I then capture the result code, which should not be an integer, it has been parsed in the methods that were called. All that seems to be running fine, but when I try to use TextView to setTextSize my application is force closing, I have tried a few different ways of implementing this setTextSize method, including not using the variable that I am getting back (resultCode) at all, and instead just plugging in a preset number, but the application is still bombing as soon as I try to call setTextSize in any way. I wanted to see if there is anything special about the setTextSize that I may be missing, or if there is a better way of setting font size at run-time.
Thanks,
Nate
Does this help at all?
I did find that post through my searching, and even calling the setTextSize using pixels it still bombs out, here is my code for making the text larger:
fontSize = resultCode;
TextView tv;
tv = (TextView)findViewById(R.id.text1);
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
I do not know if this matters or not, but the view that is being used is notes_row which is referenced by id text1, more importantly, notes_row is used to display the rows on the notes_list view.
Thanks for the help, I am new to android programming, and this is something I have had trouble with for the past 2 days.
OK well what does the stack trace look like? what errors are you getting? and i know you said you plugged in an actual number in place of the variable (just for testing), but how did you plug that number in? did you just use the number or did you use the Float or Integer object or what?
Unfortunately, I do not know what a stack trace is, if you could elaborate I would be very grateful.
When I plugged the number in directly I did it both by creating a variable of type float and assigning it a value, and using that variable in the method call, as well as just putting a number directly into the method call.
Bump. Can't figure out why a simple textview.settextsize would cause a force quit.
Sitrep: I figured out the problem with my code, but in the process caused another problem. Here is the deal, I was instantiating TextView with a view object, rather than a context, after switching the line that said TextView tv = new TextView( (TextView) findViewById(R.id.text1))) to TextView tv = new TextView(this). The problem with that is, I am trying to edit data that is in a pre-existing textview, declared in one of my xmls, and therefore creating a new one does not seem like the right way to be going, or maybe I just do not understand the way to do it.
Does anyone know a way for me to access my pre-existing TextView (created in my xml file) at run-time, or even a way to apply settings that I change on my new TextView to my pre-existing one. Is this possible or do I need to be looking for a different solution (someone suggested that I create a separate view for each text size that I want to create, and then once a user selects the text they want using a menu, just call the appropriate view) I would prefer to use a more elegant solution if possible.
Thanks for all the help so far,
Nate
Doing more reading, I see that I do in fact need to make my TextView = the one that is currently defined with the program, the problem with this is that when I put breakpoints right after where I declare this statement: TextView tv = (TextView) findViewById(R.id.text1); Under variables tv shows as a null, and I believe that is the reason that I getting the crash, I think the program is seeing null.setText...... instead of view.set....
To the top
Hi, I've made an app together with a website where you can run code like this
Code:
Toast.makeText(this, "Hello World!", Toast.LENGTH_LONG).show();
which will show a toast message in your app. Or you can read the accelerometer, files or whatever you program on the fly.
The app is just finished so it is still in a test phase. I would love to hear what you think about it.
I can't submit links yet, but if you search in the playstore for
"runondroid"
written in one word you will find the app (run on droid), the website is the same with a dot com at the end
I've been monkeying around with the app and so far it's awesome with one minor issue. How the F#@* do you make use of a class once you've defined it? I keep getting an error about expecting a class, interface, or enum.
Example:
Code:
public class Foo {
private void bar(String message) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
}
Foo.bar("baz");
This particular example will generate the exact error, in fact. Am I just brain dead this morning or is there an unusual way to finagle this into functioning?
So, this is basically a question about where i should best find my solution in this forum, im making an app (just for learning purposes) and wanted to know where i should post about that question as well. This app should only open a website in WebView, and i got that far, now i want to announce something on the website that is excluded with some CSS maybe display: none; for example.
How do i do that? I have been looking for a way to modify the CSS (This announcement is all about the app) contained in a div with a class and an id to make it easier to make that connection. (I own the website and got full control over the files on the server side.)
Bare with me, this is the first time developing anything for android ^^ Thanks!
EDIT: Just because i wrote here i found something interesting in this subject, unfortunatly it's getting late here so ill have to come back tomorrow morning an fill you in. ^^ any suggestions are still appreciated.
So i found this:
public class MyWebClient extends WebViewClient {
@override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@override
public void onPageFinished(WebView view, String url) {
view.loadUrl("document.getElementsByClassName('someClass').style.display = 'none'");
}
}
.........
final MyWebClient myWebViewClient = new MyWebClient();
mWebView.setWebViewClient(myWebViewClient);
to probably do what i asked for. any suggestions?