|
In addition to what Richard said, when editing your post, please remove any unnecessary code. Just post what is relevant to the actual problem. All else is just noise.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hello, I am new in XAMARIN, i have a simple APP in VS2022.
Here is part of the code:
public interface IRepository
{
[Get("/package/")]
Task<Resultado> GetAllData();
}
public class PaqueteServicio
{
public const string API_BASE_URL = "http://www.mi.traelopaq.net/listarpaqjson.php?text1=2264&text2=pOADSIQMASD.O398AJas&KEYAPI=ODUTRAS.9di23821@ldpli2skjs43&KEYPASo=OASmsjdu38IO1p29AA93JA0OD9K1221";
private IRepository repo;
public PaqueteServicio()
{
repo = RestService.For<IRepository>(API_BASE_URL);
}
public Task<Resultado> Get()
{
return repo.GetAllData();
}
}
Package.cs
public class Package
{
[JsonProperty("peso")]
public string Peso { get; set; }
[JsonProperty("tracking_number")]
public string TrackingNumber { get; set; }
[JsonProperty("contenido")]
public string Contenido { get; set; }
public class Resultado
{
[JsonProperty("results")]
public Package[] Results { get; set; }
}
Main:
class MainViewModel : BaseViewModel
{
private readonly PaqueteServicio paqueteServicio;
private List<Package> paqueteList;
public List<Package> PaqueteList
{
get => paqueteList;
set
{
paqueteList = value;
RaisePropertyChanged();
}
}
public ICommand ClickCommand => new Command(ClickCommandExecute);
private async void ClickCommandExecute()
{
var response= await paqueteServicio.Get();
PaqueteList = response.Results.ToList();
}
public MainViewModel()
{
paqueteServicio = new PaqueteServicio();
}
}
|
|
|
|
|
Very interesting but you forgot to ask a question. The message you see is telling you that you are trying to use a reference variable that does not have a value. This could be because you forgot to initialise it, or because some method call has not returned the reference that you expected. But either way the only way to find the offending code (and fix it) is to use the debugger and trace what your code is doing.
|
|
|
|
|
Thanks at lot,
Well, after debuggin i got this message, maybe this is really the PROBLEM:
I had read the possible solutions: But i do not get it. Sorry. Here is the code
As soon the App starts this method is executed:
public PaqueteServicio()
{
repo = RestService.For<IRepository>(API_BASE_URL);
}
and var repo get the URL value
When clicked the button: This is executed
public Task<Resultado> Get()
{
return repo.GetAllData();
}
Which it was defined here:
public interface IRepository
{
[Get("/")]
Task<Resultado> GetAllData();
}
Where Resultado is this (a class)
public class Resultado
{
[JsonProperty("results")]
public Package[] Results { get; set; }
}
And Package is my json file:
public class Package
{
[JsonProperty("peso")]
public string Peso { get; set; }
[JsonProperty("tracking_number")]
public string TrackingNumber { get; set; }
[JsonProperty("contenido")]
public string Contenido { get; set; }
}
|
|
|
|
|
Sorry, I do not know what that is supposed to mean. You need to trap the actual instruction that throws the exception.
|
|
|
|
|
Well, I just changed the code complete:
async void Button_Clicked(System.Object sender, System.EventArgs e)
{
var httpClient = new HttpClient();
var resultJson = await httpClient.GetStringAsync("http://www.mi.traelopaq.net/listarpaqjson.php?text1=2264&text2=pOADSIQMASD.O398AJas&KEYAPI=ODUTRAS.9di23821@ldpli2skjs43&KEYPASo=OASmsjdu38IO1p29AA93JA0OD9K1221");
var resultList = JsonConvert.DeserializeObject<Package[]>(resultJson);
PaqueteList.ItemsSource = resultList;
}
And Package is my json file:
public class Package
{
[JsonProperty("peso")]
public string Peso { get; set; }
[JsonProperty("tracking_number")]
public string TrackingNumber { get; set; }
[JsonProperty("contenido")]
public string Contenido { get; set; }
}
If you use postman and type the URL:
"http://www.mi.traelopaq.net/listarpaqjson.php?text1=2264&text2=pOADSIQMASD.O398AJas&KEYAPI=ODUTRAS.9di23821@ldpli2skjs43&KEYPASo=OASmsjdu38IO1p29AA93JA0OD9K1221"
You got an answer, but not in the programa, if it the same Error: Object Set without... and it is correct because there is not answer, But WHY? because it is works on postman.
|
|
|
|
|
I have explained why, and how to find the problem. I am afraid I cannot offer any more suggestions.
|
|
|
|
|
Solution:
I just changed the code to:
HttpWebRequest wReq = WebRequest.Create("http://www.mi.traelopaq.net/listarpaqjson.php?text1=2264&text2=pOADSIQMASD.O398AJas&KEYAPI=ODUTRAS.9di23821@ldpli2skjs43&KEYPASo=OASmsjdu38IO1p29AA93JA0OD9K1221") as HttpWebRequest;
string json = null;
using (HttpWebResponse wResp =(HttpWebResponse) wReq.GetResponse())
{
using (Stream s = wResp.GetResponseStream())
{
using (TextReader tr = new StreamReader(s))
{
json = tr.ReadToEnd();
MessageBox.Show(json);
}
}
}
and i can read the URL without problem
|
|
|
|
|
NB: The as operator can and will return null if the object you're trying to cast cannot be converted to the target type.
Type-testing operators and cast expression - C# reference | Microsoft Docs[^]
You use as when you're not sure whether the object can be converted to the specified type; in which case, you should always check for null before using the variable. Using T y = x as T; without then checking for y == null is always a mistake.
When you're certain that the object will be of the desired type, you use a cast expression instead: T y = (T)x; In this case, there is no need to check for null , since the runtime would throw an exception if the conversion cannot be performed.
However, in this case, it would be far better to simply use the WebRequest.CreateHttp method, which has been available since .NET 4.5, and already returns the correct type:
WebRequest.CreateHttp Method (System.Net) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Is is realistic to make money from a small mobile/tablet app? That's a ridiculously vague question, I know, so I'll add a bit of background.
I'm coming to the end of a long project that has increased my experience of mobile application programming (using Xamarin and C#). I don't yet have another contract lined up. What I do have are ideas for two or three small applications, the smallest of which may take only about a month-or-so to get to a first version. Judging by other applications I have seen in the app store, I'd say that my application is something someone might pay £0-99 or £1-99 to get the Pro version (which I'd advertise in the Standard version). And I am wondering if I can make a few quid?
I don't expect to make much but even £10-£50 per month is still money in the bank. I don't seem to be able to get any kind of answer anywhere whether this is remotely likely. I guess I am hoping that one of you out there has personal experience of this and could at least sketch me an outline of whether this is even worth a go.
Absolutely any advice would be extremely welcome.
- Patrick
Thank you to anyone taking the time to read my posts.
|
|
|
|
|
I don't have the answer, but it is probably worth spending time at the app store(s). Are there any other apps that are similar, and what sort of comments are people making about them? What sort of comments do you see on any apps that are only vaguely similar? One of the main take homes from the comments is finding out what the public want to see from their apps.
|
|
|
|
|
Good advice, Richard, and something I haven't done enough of.
Thank you to anyone taking the time to read my posts.
|
|
|
|
|
You can sell a few; depends on the app. If it's another "pdf reader", probably not.
If it's an app you wouldn't use yourself; probably not.
My current app will be a first of a kind; I'll see what it does. My other apps are similar to some others; I just made mine better (or tried).
In the Microsoft store, you pay higher fees to MS (30%) for games you sell than for others (10%). Although my apps have a "gaming" aspect to them, I have them in the "reference" section because they have a historical aspect. (Which gave me material for more ideas)
Anyway, there are "thousands" of apps; so you get to dabble in "box art" and "marketing" to get your app noticed (and "moved" in the listings). The Store gives you a page for your app; so you get some analytics to work with.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Thank you, Gerry. Some things in there I had thought about but maybe not thought enough about.
(I didn't even know Microsoft had an app store, at least one that you maybe can make money out of.)
Thank you to anyone taking the time to read my posts.
|
|
|
|
|
I agree with the Microsoft store part.
|
|
|
|
|
The Microsoft app store might be a good idea.
I guess that your app might be a stand-alone executable, if so then be careful how you write your XML that you include in the executable. It is not complicated. Microsoft has some guidelines that help you get on their list.
Do it. Make some money. Do not be afraid of competition. Do not worry about competition so much that you do not have a product out there.
Thank you for asking.
|
|
|
|
|
Hi
I program business logik in ERP systems in Visual Studio with vb.net and C#.
Now I would like to try and learn to make app's so maybe one day and I can make app's that show business data.
But beeing new to this I find it difficult to get started. There is a lot of new words I don't know the meaning of and it is difficult to find out how to best start making app's.
I started looking at Xamarin beeing used to VS and all, but I just found out that this seems to be obsolete?
I would like to only write code once and use it on both android and ios - but is this realistic?
So...
Any recommendations where to start?
A good place be be guided through which buzz words I need to know about and the technology they represent?
Should I use Xamarin, or Flutter or...???
Hands on example that makes it easy to learn by doing?
Any recommendations will be appreciated
Another old dog that wants to learn new tricks
|
|
|
|
|
|
|
Growing in Mobile Development Popularity
Hybrid applications are going to become more and more critical in the future.
It does not make sense to learn Java or hire Java developer for developing Android apps and to learn Objective-C / Swift to develop IOS applications and learn C# or hire a C# developer to develop Windows 10 phone applications.
|
|
|
|
|
Use Maui in Visual Studio (the Xamarin successor)
|
|
|
|
|
|
What are you trying to accomplish with this message?
|
|
|
|
|
It's a closed spam account.
More to the point, what are you trying to accomplish with your message?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|