|
Dear mr. MacCutchan Thank you very much for your answer, and yes your guess is correct Iam getting the exception on this line
msg.replyTo.send(message);
I am a novice on Android programming and I tried to debug the program. This is what I get from the debugger
this = {RuntimeInit$UncaughtHandler@4000}
t = {Thread@3564} "Thread[main,5,main]"
e = {NullPointerException@4001} "java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Messenger.send(android.os.Message)' on a null object reference"
cause = {NullPointerException@4001} "java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Messenger.send(android.os.Message)' on a null object reference"
detailMessage = "Attempt to invoke virtual method 'void android.os.Messenger.send(android.os.Message)' on a null object reference"
stackState = {Object[9]@4006}
stackTrace = {StackTraceElement[0]@4007}
suppressedExceptions = {Collections$EmptyList@4008} size = 0
shadow$_klass_ = {Class@2610} "class java.lang.NullPointerException"
shadow$_monitor_ = -2090121786
Quote: I've also tried to specify the handler directly like so:
Quote:
msg.replyTo = new Messenger(new ServiceHandler());
serviceMessenger.send(msg);
Quote: but I'm getting another exception on line serviceMessenger.send(msn);
java.lang.IllegalStateException: { when=0 what=1 target=com.seber.lisah.BluetoothService$ServiceHandler } This message is already in use.
|
|
|
|
|
You need to go back to the original error and find out why msg or replyTo are null. As I said earlier, we cannot diagnose the state of your objects. If nothing obvious shows up then you need to check the documentation to make sure that you are creating the objects correctly. Randomly changing the code before you have diagnosed the error is not likely to help you.
|
|
|
|
|
Member 11911065 wrote:
I am a novice on Android programming... Which is probably a good reason to start with a few simpler programs before diving into services and IPC programs. Tracking down null pointer exceptions is a fundamental task, so if that is giving you trouble, it's time to take a step (or two) back and get the basics nailed down real good.
"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
|
|
|
|
|
Sir I have problem. Let suppose that I have data like 23,56,89,88,90,1234,3445. now I want to add them all and want to get result. but this code is giving me result like that 23+56+36=92 not 115. mean it make addition of just to previous values
Here is my code
**************
package com.example.maher.androidspinnertutorial;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class calculatr extends AppCompatActivity {
Button btn_1,btn_2,btn_3,btn_4,btn_5,btn_6,btn_7,btn_8,btn_9,btn_0,btn_Add,btn_Sub,btn_Mul,btn_Div,btn_calc,btn_dec,btn_clear;
EditText ed1;
float Value1, Value2;
boolean mAddition, mSubtract, mMultiplication, mDivision ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculatr);
btn_0 = (Button) findViewById(R.id.btn_0);
btn_1 = (Button) findViewById(R.id.btn_1);
btn_2 = (Button) findViewById(R.id.btn_2);
btn_3 = (Button) findViewById(R.id.btn_3);
btn_4 = (Button) findViewById(R.id.btn_4);
btn_5 = (Button) findViewById(R.id.btn_5);
btn_6 = (Button) findViewById(R.id.btn_6);
btn_7 = (Button) findViewById(R.id.btn_7);
btn_8 = (Button) findViewById(R.id.btn_8);
btn_9 = (Button) findViewById(R.id.btn_9);
btn_Add = (Button) findViewById(R.id.btn_Add);
btn_Div = (Button) findViewById(R.id.btn_Div);
btn_Sub = (Button) findViewById(R.id.btn_Sub);
btn_Mul = (Button) findViewById(R.id.btn_Mul);
btn_calc = (Button) findViewById(R.id.btn_calc);
btn_dec = (Button) findViewById(R.id.btn_dec);
btn_clear = (Button) findViewById(R.id.btn_clear);
ed1 = (EditText) findViewById(R.id.edText1);
btn_0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"0");
}
});
btn_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"1");
}
});
btn_2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"2");
}
});
btn_3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"3");
}
});
btn_4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"4");
}
});
btn_5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"5");
}
});
btn_6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"6");
}
});
btn_7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"7");
}
});
btn_8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"8");
}
});
btn_9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"9");
}
});
btn_dec.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+".");
}
});
btn_Add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value1 = Float.parseFloat(ed1.getText() + "");
mAddition = true ;
ed1.setText(null);
}
});
btn_Sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value1 = Float.parseFloat(ed1.getText() + "");
mSubtract = true ;
ed1.setText(null);
}
});
btn_Mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value1 = Float.parseFloat(ed1.getText() + "");
mMultiplication = true ;
ed1.setText(null);
}
});
btn_Div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value1 = Float.parseFloat(ed1.getText()+"");
mDivision = true ;
ed1.setText(null);
}
});
btn_calc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value2 = Float.parseFloat(ed1.getText() + "");
if (mAddition == true){
ed1.setText(Value1 + Value2 +"");
mAddition=false;
}
if (mSubtract == true){
ed1.setText(Value1 - Value2 +"");
mSubtract=false;
}
if (mMultiplication == true){
ed1.setText(Value1 * Value2 + "");
mMultiplication=false;
}
if (mDivision == true){
ed1.setText(Value1 / Value2+"");
mDivision=false;
}
}
});
btn_clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText("");
}
});
}
}
****************
could anyone help me please?/
|
|
|
|
|
You are treating each part of the calculation as the complete result, rather than saving the interim value. When you click the + button you set Value1 equal to the number in the txt box. But next time you press the + button you overwrite Value1. So typing 23+56+36 actually only gives the result of 56+36, which is 92. You need to keep a running total as each operator button is pressed. So the sequence should be something like:
Set Value1 to zero
set next operator to +
DO
if an operator button is pressed
if it is the '=' operator
display the result
else
parse the text into the number
apply the current operation to Value1 (i.e add, subtract etc. this number to Value1)
set the 'next' operator to the pressed button
WHILE operator is not '='
|
|
|
|
|
Hi, my name is Mustafa. I am from Turkey.
I do not know your language, so I'm getting help from Google Translate.
Sample code on Windows Visual Basic.
İF WebBrowser.DocumentText.Contains("404")
MsgBox("This page can not be reached.")
I want to implement this code in xamarin WebView as well. How do I do that?
I've been searching from here. This is sample code. but I'm getting an error
|
|
|
|
|
What EXACTLY are you needing help with? Do you have an Android app that is using a WebView control and you are wanting to know if a requested page could not be loaded, or do you need help displaying a "message box" to the user?
If the former, call setWebViewClient() on your WebView object and listen for the 404 error in the onReceivedError() method.
"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
|
|
|
|
|
First of all thank you for your response.
I want to search for a post on the Web page.I want to tell you what I want to tell you with Picture.
http://anadolufilms.com.tr.ht/ocean/1.png
http://anadolufilms.com.tr.ht/ocean/2.png
That's what I want to do How is this done with Xamarin WebView?
|
|
|
|
|
I see code, so what is, or isn't, working for you?
"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
|
|
|
|
|
Since android code is visible for attackers, I want to change the name of variables and functions
I know there are some tools for android obfuscation but I want to add more security
I think I should have an excel file with 2 columns (1 - unique old names 2 - unique new names)
Then utilizing a tool replace the old names with the new ones
Any suggestion?
|
|
|
|
|
Replacing meaningful names by something else makes code not more secure. It makes it just a little bit harder to reproduce what the code is doing.
Recommended read: Security through obscurity - Wikipedia[^] and other sources about that term.
If you really want to do it:
Because source code files are text files, it is a job for simple search & replace which can be automated using regular expressions iterating over the values of an input file (CSV would be better / simpler to use than Excel) and a list of source files. With Linux I would use a shell script for all the stuff except the replace which can be done with sed.
|
|
|
|
|
|
The tools are provided by the console (PowerShell with Windows, bash with Linux). They are able to iterate over files in a directory (with an optional search mask and optionally including sub directories). You can even read column separated text files there line by line and use that data to perform the replacement (executing sed with Linux or again PowerShell commands with Windows).
|
|
|
|
|
|
AndroidVH wrote: Then utilizing a tool replace the old names with the new ones Android Studio already does this:
Refactor --> Rename
"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
|
|
|
|
|
i have an array list
lsCategory = new ArrayList<>();
lsCategory.add(new category("fffff","sssssss","ssssddd",R.drawable.thump));
lsCategory.add(new category("ddd","sssssss","ssssddd",R.drawable.thump));
i need to add more elements after my api call responce
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("employees");
for (int i = 0; i < jsonArray.length();i ++)
{
JSONObject employee = jsonArray.getJSONObject(i);
Integer id = employee.getInt("id");
String title = employee.getString("first_name");
Object item = new category("tttt","dynamic","ssssddd",R.drawable.thump);
lsCategory.add((category) item);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
But the item inside the response code not adding in to array list ( lsCategory ) only getting 2 elements which add in top , any solution guys?
|
|
|
|
|
Are you certain that the code inside that loop is actually gone through? Try adding some logging code to see what is happening.
|
|
|
|
|
Yes , it is looping , i just added a toast inside the loop and it is showing
|
|
|
|
|
Check the return value from the call to add. Or there is something else happening that we cannot see.
|
|
|
|
|
rathilesh c wrote: ...only getting 2 elements... 1) How are you verifying this?
2) What do you see if you add the following:
lsCategory.add((category) item);
Log.d(TAG, "Size = " + lsCategory.size());
3) Is an exception being thrown?
"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
|
|
|
|
|
I'm newbie to Android and PHP but I've decided to make a professional e-commerce application
The php code is responsible to upload images and json files to the server
Users download and upload from the server
I've been electronic project manager for some years and I somewhat know how to do a project
I somewhat know what is DFMEA, automatic validation, documentation, risk management , ...
But since I'm new to this type of project, I'm always afraid of being confronted by something in the darkness while perhaps that thing is a very preliminary issue for even begginers
hence, I need your help
Even if this is a very very general question and normally is not a norm in forums, I hope you help me
If you have something in mind which may be helpful, please mention
It could be any type of information if you think it may be neglected even if it is very simple issue
For example, recently I understand something about passwords of the users:
It should not be stored in the database and something like MD5 should be used and the password should be salted and then the values be stored
Thanks in advance
|
|
|
|
|
AndroidVH wrote: I'm newbie to Android and PHP but I've decided to make a professional e-commerce application The first question I would ask is why you think Android is going to be useful here? PHP is fine for e-commerce, as you want to run it on a web server. Where do you think Android will fit into the project?
|
|
|
|
|
I got your point, you mean just a mobile responsive website design is enough?
In fact to be honest I just saw many different applications which were designed for such a case
Now that you're asking this question I have to think and find out the benefits of the app
I read this nice article:
Mobile Website vs. Mobile App (Application) – Which is Best for Your Organization? | Human Service Solutions[^]
When I utilize app cause:
1 - I can be able not to ask customers to type a special address and go to my site
2 - I need camera to take a photo and upload it as a product
3 - I think app is better than website from popeganda point of view (It is more attractive)
4 - I can send advertising pop up's to special customers
5 - ...
|
|
|
|
|
Yes, you can do all those things. However, the e-commerce service must run on a website so your users can get access to it. That means it needs to be accessible via internet browsers. Creating an Android app to give the same service is a separate project. So you need one team to build the website, and another team to create the Android app, and most likely one for iOS.
|
|
|
|
|
Yes, I have plan for both but for now I have concentrated on the app which needs a server
I thank you for your point (I did something but I didn't know why and now I know)
Would you please continue if there are some other points?
|
|
|
|