当我使用progress.xml
文件中的资源时,我收到ResourcesNotFoundException异常。
我的完整代码位于Error,class.java,progress.xml文件。
Logcat中的错误
09-04 00:39:04.700: E/AndroidRuntime(17837): FATAL EXCEPTION: main
09-04 00:39:04.700: E/AndroidRuntime(17837): Process: developer.mohab.gymee, PID: 17837
09-04 00:39:04.700: E/AndroidRuntime(17837): java.lang.RuntimeException: Unable to start activity ComponentInfo{developer.mohab.gymee/developer.mohab.gymee.Cardio.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
09-04 00:39:04.700: E/AndroidRuntime(17837): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
09-04 00:39:04.700: E/AndroidRuntime(17837): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
09-04 00:39:04.700: E/AndroidRuntime(17837): at android.app.ActivityThread.access$800(ActivityThread.java:149)
09-04 00:39:04.700: E/AndroidRuntime(17837): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
09-04 00:39:04.700: E/AndroidRuntime(17837): at android.os.Handler.dispatchMessage(Handler.java:102)
09-04 00:39:04.700: E/AndroidRuntime(17837): at android.os.Looper.loop(Looper.java:211)
09-04 00:39:04.700: E/AndroidRuntime(17837): at android.app.ActivityThread.main(ActivityThread.java:5333)
09-04 00:39:04.700: E/AndroidRuntime(17837): at java.lang.reflect.Method.invoke(Native Method)
09-04 00:39:04.700: E/AndroidRuntime(17837): at java.lang.reflect.Method.invoke(Method.java:372)
09-04 00:39:04.700: E/AndroidRuntime(17837): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
Class返回此错误
public static class Progress extends Fragment {
TextView Abs ;
TextView Per ;
MainActivity mainActivity ;
Database database ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainActivity = (MainActivity) getActivity();
database = new Database(getActivity());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.progress,container,false);
Abs = (TextView) view.findViewById(R.id.above);
Per = (TextView) view.findViewById(R.id.below);
Prgress_Limits();
return view ;
}
public void Prgress_Limits(){
Cursor cursor ;
cursor = getCursor();
int LAST_INPUT ;
int FIRST_INPUT ;
if(cursor!=null&&cursor.moveToFirst()) {
int VALUE_COLUMN = cursor.getColumnIndex(Contract.Cardio_chart.Values.VALUE);
FIRST_INPUT = cursor.getInt(VALUE_COLUMN);
cursor.moveToLast();
LAST_INPUT = cursor.getInt(VALUE_COLUMN);
int abs = LAST_INPUT-FIRST_INPUT ;
Abs.setText(abs);
int per = (abs*100)/FIRST_INPUT ;
Per.setText(per+" %");
}
else {
Abs.setText(00);
Per.setText(00+" %");
}
}
public Cursor getCursor() {
Cursor c;
String Selection;
Cursor check;
ContentResolver hesolver = getActivity().getContentResolver();
check = hesolver.query(DatabaseFilter.ValueTable(), null, null, null, null);
Cursor check2;
ContentResolver resolver = getActivity().getContentResolver();
check2 = resolver.query(DatabaseFilter.LimitTable(), null, null, null, null);
if (check != null && check.moveToFirst() && check2 != null && check2.moveToFirst()) {
int Offset = offset();
int Limit = limit();
Selection = "SELECT * FROM " + DatabaseFilter.valueTable_Name() + " LIMIT " + Limit + " OFFSET " + Offset + ";";
SQLiteDatabase db = database.getReadableDatabase();
c = db.rawQuery(Selection, null);
} else {
ContentResolver sesolver = getActivity().getContentResolver();
c = sesolver.query(DatabaseFilter.ValueTable(), null, null, null, null);
}
return c;
}
public int offset() {
Cursor save;
ContentResolver resolver = getActivity().getContentResolver();
save = resolver.query(DatabaseFilter.LimitTable(), null, null, null, null);
save.moveToLast();
int high = save.getColumnIndex(Contract.Cardio_chart.Limits.HIGH);
int Offset = save.getInt(high);
save.close();
return Offset;
}
public int limit() {
Cursor h;
ContentResolver resolver = getActivity().getContentResolver();
h = resolver.query(DatabaseFilter.ValueTable(), null, null, null, null);
h.moveToLast();
int id = h.getColumnIndex(Contract.Cardio_chart.Values._ID);
int last_chart_input = h.getInt(id);
int Offset = offset();
int Limit = last_chart_input - Offset;
h.close();
return Limit;
}
}
}
当我使用progress.xml
文件
Progress.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="49dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:id="@+id/relative">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/progress"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Progress"
android:id="@+id/textView"
android:autoText="false"
android:textColor="#ff538dff"
android:textSize="@dimen/abc_dialog_padding_top_material"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView2"
android:layout_toEndOf="@+id/textView2"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text=" absolute"
android:id="@+id/textView2"
android:textIsSelectable="true"
android:textSize="@dimen/abc_action_bar_icon_vertical_padding_material"
android:textColor="#ffffb75d"
android:gravity="center"
android:layout_alignTop="@+id/above"
android:layout_alignRight="@+id/textView4"
android:layout_alignEnd="@+id/textView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/above"
android:layout_below="@+id/textView"
android:layout_toRightOf="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:background="#ffd8f1ff"
android:padding="5dp"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text=" percentage"
android:id="@+id/textView4"
android:textSize="@dimen/abc_action_bar_icon_vertical_padding_material"
android:textColor="#ffffbd56"
android:gravity="center"
android:layout_below="@+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/below"
android:background="#ffd8f1ff"
android:padding="5dp"
android:layout_below="@+id/above"
android:layout_alignLeft="@+id/above"
android:layout_alignStart="@+id/above" />
答案 0 :(得分:0)
设置文本时不要输入整数,而是使用字符串
Abs.setText("00");
Per.setText("00 %");
如果您想使用ressource作为替代方案,那么这里有一个例子:
Abs.setText(getResources().getString(R.string.zero_string));