• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps ASCII CONVERTER!

HI everyone Sorry But I cant put up much Information right now!

Im on the verge of completing my First Android Application Idea But i Cant pull it off I feel down right now please help me !! Im just trying to cast a Character to a integer so that i can get the ascii decimal value of a character but it says there was an error so i tried it first on pure java it works but then when i applied it on android studio theres a error i screen shot the error thanks

Java CLass file
package renzcalc.com.renzascii;

import android.os.DropBoxManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.animation.Interpolator;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText user_input;
TextView result;

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
user_input= (EditText)findViewById(R.id.input);
result=(TextView)findViewById(R.id.ans);
}

public void get_ascii(View view)
{
user_input.addTextChangedListener(new TextWatcher() {
@override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@override
public void afterTextChanged(Editable editable) {

String x= user_input.getText().toString();
Character y = x.charAt(0);
Integer yeah= (Integer)y;

}
});
}
}


XML file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="renzcalc.com.renzascii.MainActivity">


<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Character.."
android:fontFamily="cursive"
android:onClick="get_ascii"
android:id="@+id/input"
/>

<android.support.v7.widget.AppCompatAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Numeric ASCII Equivalent"
android:layout_below="@id/input"
android:id="@+id/ans"
/>

</RelativeLayout>
 

Attachments

  • problem.png
    problem.png
    154.3 KB · Views: 95
You can't do this in Java. It's not like C++ where there are all kinds of implicit casting rules between object types.
To get the ASCII numeric value of a char, just cast it to a primitive int type.

Code:
int charValue = (int) x.charAt(0);
 
You can't do this in Java. It's not like C++ where there are all kinds of implicit casting rules between object types.
To get the ASCII numeric value of a char, just cast it to a primitive int type.

Code:
int charValue = (int) x.charAt(0);

Thanks Master !! I should read about that!
Your a big help
 
Back
Top Bottom