Emanuel Paul Mnzava Emanuel Paul Mnzava - 11 days ago 5
Android Question

Error:android.content.res.Resources$NotFoundException: String resource ID #0x1

Am getting an error saying resource id can't be found tried tracing the problem the code seems fine

This area contains my class that uses the xml resource below to show all the necessary elements anyone who can help to tell me why am getting such an error

@Bind(R.id.showfirstname)
MyEditText Myfirstname;

@Bind(R.id.showlastname)
MyEditText Mylastname;

@Bind(R.id.showEmail)
MyEditText Myemail;

@Bind(R.id.profilephone)
MyEditText Mytel;



private Source mDataSource = new Source(this);

Cursor userDataCursor;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_profile);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);


ButterKnife.bind(this);

mDataSource.open();

userDataCursor = mDataSource.selectUserData();
userDataCursor.moveToFirst();


Myfirstname.setText(userDataCursor.getColumnIndex("firstname"));
Myfirstname.setEnabled(false);
Mylastname.setText(userDataCursor.getColumnIndex("lastname"));
Mylastname.setEnabled(false);
Myemail.setText(userDataCursor.getColumnIndex("email"));
Myemail.setEnabled(false);
Mytel.setText(userDataCursor.getColumnIndex("tel"));
Mytel.setEnabled(false);




mDataSource.close();

}



My xml file is here


This is my resource 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.itekit.UserProfile"
android:background="#fff">

<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/fronTheme"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Profile"
android:layout_gravity="left"
android:id="@+id/toolbar_title"
android:textColor="#ffffff"
android:textSize="18dp" />

</android.support.v7.widget.Toolbar>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/my_toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">

<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/userdp"
android:src="@drawable/userdp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp" />

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="327dp">

<LinearLayout
android:id="@+id/linear1"
android:layout_below="@+id/setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="22dp"
>



<LinearLayout
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<custom_font.MyTextViewSemiBold
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="First Name"
android:textColor="#a9b0c3"
android:textSize="14dp"
/>

<custom_font.MyEditText
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Emmanuel"
android:textColor="#1B5E20"
android:textSize="14dp"
android:id="@+id/showfirstname"
/>
</LinearLayout>




<LinearLayout
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<custom_font.MyTextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Last Name"
android:textColor="#a9b0c3"
android:textSize="14dp"
/>

<custom_font.MyEditText
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mnzava"
android:textColor="#1B5E20"
android:textSize="14dp"
android:id="@+id/showlastname"
/>
</LinearLayout>



<LinearLayout
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<custom_font.MyTextViewSemiBold
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email"
android:textColor="#a9b0c3"
android:textSize="14dp"
/>

<custom_font.MyEditText
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Emma@primeware.co.tz"
android:textColor="#1B5E20"
android:textSize="14dp"
android:id="@+id/showemail"
/>
</LinearLayout>


<LinearLayout
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<custom_font.MyTextViewSemiBold
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PhoneNumber"
android:textColor="#a9b0c3"
android:textSize="14dp"


/>


<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<custom_font.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+255 - "
android:textColor="#1B5E20"

android:textSize="14dp"
android:background="#00000000"

android:id="@+id/tznumber"
/>

<custom_font.MyEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="687 851 503"
android:textColor="#1B5E20"
android:textColorHint="#a9b0c3"
android:textSize="14dp"
android:background="#00000000"
android:id="@+id/profilephone"

android:inputType="phone" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<custom_font.MyTextViewSemiBold
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password"
android:textColor="#a9b0c3"
android:textSize="14dp"
/>

<custom_font.MyEditText
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Emma@primeware.co.tz"
android:inputType="textPassword"
android:textColor="#1B5E20"
android:textSize="14dp"
android:id="@+id/showEmail"

/>
</LinearLayout>


</LinearLayout>




</LinearLayout>

<custom_font.MyTextView
android:id="@+id/createAccount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save"
android:textStyle="bold"
android:background="@drawable/round"
android:textColor="#CBD1DC"
android:gravity="center"
android:padding="14dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textSize="16dp" />

</LinearLayout>

</RelativeLayout>

Answer

The getColumnIndex method won't give you the value of that column. It only gives you the index of that column in your database.

You should do it like this:

userDataCursor.getString(userDataCursor.getColumnIndex("firstname"));

Comments