Please help me, I can't figure out why this error. Just a day ago it worked.
I understand the it serches for and id ist'n existing but the id is there in the xml.
It give me error here, in onCreate
method:
public class DoExamActivity extends Activity {
private DatabaseHandler db;
private EditText votoET;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.do_exam);
Bundle bundle = getIntent().getExtras();
db = new DatabaseHandler(getApplicationContext());
try {
transcript = new JSONObject(bundle.getString("transcript"));
exam = new JSONObject(bundle.getString("exam"));
teacher = new JSONObject(bundle.getString("teacher"));
} catch (JSONException e) {
e.printStackTrace();
}
votoET = (EditText) findViewById(R.id.examValueET); //here
This is the do_exam.xml
of the edit text he cant find. You can see the id is there!
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_height="30dp"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:background="@color/ios7orange"
android:contentDescription="@string/textValueDescr"
android:src="@drawable/rating_star" />
<TextView
android:layout_height="50dp"
android:layout_weight="1" />
<EditText
android:id="@+id/examValueET"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:layout_weight="5"
android:background="@drawable/rounded_edittext"
android:hint="@string/examValueHint"
android:inputType="text"
android:maxLines="1" />
</TableRow>
Give me this error:
11-13 07:04:15.457: E/AndroidRuntime(1091): FATAL EXCEPTION: main
11-13 07:04:15.457: E/AndroidRuntime(1091): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.utaa.iesami/com.utaa.iesami.activity.DoExamActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.os.Looper.loop(Looper.java:137)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-13 07:04:15.457: E/AndroidRuntime(1091): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 07:04:15.457: E/AndroidRuntime(1091): at java.lang.reflect.Method.invoke(Method.java:525)
11-13 07:04:15.457: E/AndroidRuntime(1091): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-13 07:04:15.457: E/AndroidRuntime(1091): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-13 07:04:15.457: E/AndroidRuntime(1091): at dalvik.system.NativeStart.main(Native Method)
11-13 07:04:15.457: E/AndroidRuntime(1091): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.content.res.Resources.getText(Resources.java:239)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.widget.TextView.setText(TextView.java:3844)
11-13 07:04:15.457: E/AndroidRuntime(1091): at com.utaa.iesami.activity.DoExamActivity.onCreate(DoExamActivity.java:61)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.app.Activity.performCreate(Activity.java:5133)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-13 07:04:15.457: E/AndroidRuntime(1091): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-13 07:04:15.457: E/AndroidRuntime(1091): ... 11 more
I searched in the R class and the id of that EditText
is there and is different from 0. So why this error?
CODE UPDATED
I already cleaned, nothing. The activity it's too big, I added the code until the row of the error. So I used the caps for all the IDs, it worked for two week, now it give me error just on that ET.
My error. I mistaked the rows, the error was from a TextView.setText(int)
where I had to set TextView.setText(String.valueOf(int))
.
Just as @laalto said:
you're calling essentially setText(0) on your EditText. If you want to set the edittext value to 0, use setText(String) instead of setText(int).
But i assume it's not your fault because the value of int might be dynamic (called from a data source - DB), this was the case for me and i had to box the value of int i.e
instead of
setText(int)
use
setText(String.valueOf(int))
Hope this helps you Or someone! Happy Coding!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With