代码末尾的解释
爪哇:
void GetNextQuestion()
{
QuestNum++;
/// ERROR ON VERY NEXT LINE
ProgressBar pbar = (ProgressBar)this.findViewById(R.id.progressBar2);
TextView tvSection = (TextView)this.findViewById(R.id.section);
TextView tvSubsection = (TextView)this.findViewById(R.id.subsection);
TextView tvQuest = (TextView)this.findViewById(R.id.quest);
if(QuestNum > 0 && QuestNum < 180)
{
tvSection.setText(R.string.s1);
tvSubsection.setText(R.string.ss1);
spin.setSecondaryProgress((int)((QuestNum/180) * 1000));
}
if(QuestNum > 179 && QuestNum < 285)
{
tvSection.setText(R.string.s2);
tvSubsection.setText(R.string.ss2);
}
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/lib/com.google.ads">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:id="@+id/icon"
android:layout_width="57dp"
android:layout_height="54dp"
android:src="@drawable/devil" />
<TextView
android:id="@+id/section"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/icon"
android:text="@string/nunca"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="invisible" />
<TextView
android:id="@+id/subsection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/section"
android:layout_alignParentRight="true"
android:layout_below="@+id/icon"
android:text="@string/nunca"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="@+id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/helpico" />
<ImageView
android:id="@+id/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/subsection"
android:layout_alignParentRight="true"
android:src="@drawable/exitico" />
<TextView
android:id="@+id/haveyou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/subsection"
android:layout_marginTop="18dp"
android:text="@string/nunca"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/quest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/load"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/butyes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_above="@+id/progressBar2"
android:layout_marginBottom="30dp"
android:text="Yes" />
<Button
android:id="@+id/butno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="@+id/progressBar2"
android:layout_marginBottom="30dp"
android:text="No" />
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:max="1000"
android:progress="0"/>
</RelativeLayout>
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="a14ffb06b21e68e"
app:loadAdOnCreate="true" >
</com.google.ads.AdView>
</LinearLayout>
错误:
E/AndroidRuntime(20649): FATAL EXCEPTION: main
E/AndroidRuntime(20649): java.lang.ClassCastException: android.widget.Button
at com.ndai.ptest.a1000test.GetNextQuestion(a1000test.java:146)
at com.ndai.ptest.a1000test$QuestAnsTask.onPostExecute(a1000test.java:3319)
at com.ndai.ptest.a1000test$QuestAnsTask.onPostExecute(a1000test.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
这是我不明白的...它给了我一个铸造错误...我正在铸造一个进度条tp一个进度条...我只是错过了一个错字或什么...我只需要一组额外的盯着这个
编辑:
但是,直到我重新排列 xml 上的内容后,我才收到此错误