nck nck - 1 year ago 87
Android Question

getText().toString() adds some numbers before what is typed

I have instanced the variable:

editname = (EditText) findViewById(;

Then on click of a button I want to put it in a database:

if (editname.getText().toString().matches("")){
if (myDB.insertData(editname.getText().toString()){//Insert data
Toast.makeText(..., R.string.data_inserted + check_value, Toast.LENGTH_LONG).show();

Once it is on the database I send it to a fragment after a click on a button:

Fragment newFragment = new PreviewFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();

String get_id = Integer.toString(myDB.getId(check_value)); //Get ID //java.lang.NullPointerException
Bundle bundle = new Bundle();
bundle.putString("id", get_id);
transaction.replace(, newFragment);

On the implementation of the fragment:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view;
view = inflater.inflate(R.layout.fragment1, container, false);
String id;

try {
id = getArguments().getString("id");
}catch (Exception e){
Toast.makeText(getActivity(), "not found", Toast.LENGTH_LONG).show();
return view;

Cursor res = myDB.getValues(id);

And in that line I see java.lang.NullPointerException

Once I added the check_value I could see that the text I got was not what I introduced in the box but this:

2131099688(Followed by the text I introduced)

Anyone knows the reason for this? I already removed the app and cleaned the project but I still get the same.

Answer Source

It is just the result of what you put in your toast.

Toast.makeText(..., R.string.data_inserted + check_value, Toast.LENGTH_LONG).show();

The number before check_value is the id of the string data_inserted.

Try to getString(R.string.data_inserted) instead of the id.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download