我的应用程序不幸停止可能是由于错误

时间:2015-08-23 09:49:01

标签: java android

我的应用程序由级别组成,每个级别有10个问题。这是我的第一级和第一级问题..

public class level1 extends ActionBarActivity {

private EditText mans1;
private TextView mcount;
int  sum;
public void Onclick(View v) {
    mans1 = (EditText) findViewById(R.id.ans1);
    mcount = (TextView) findViewById(R.id.count);
    double answer = Double.parseDouble(mans1.getText().toString());

    if (answer == (8 + 7))
    {
        Toast.makeText(level1.this, "الإجابة صحيحة", Toast.LENGTH_LONG).show();
        mcount.setText(sum++);
    }
    else
    {
        Toast.makeText(level1.this, "الإجابة خاطئة", Toast.LENGTH_LONG).show();
        mcount.setText(sum);
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_level1);

    final TextView texview = (TextView)findViewById(R.id.count);
    Button sendButton = (Button)findViewById(R.id.tm);
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            int count = Integer.parseInt(texview.getText().toString());
            Intent intent = new Intent(getApplicationContext(), level1.class);
            intent.putExtra("mycount", sum);
            startActivity(intent);
        }
    });

}

public void buttonOnClickgo(View v) {

    Button next = (Button) v;
    startActivity(new Intent(getApplicationContext(), level1q2.class));

}

public void buttonOnClickBack(View v) {

    Button back = (Button) v;
    startActivity(new Intent(getApplicationContext(), Activity2.class));
}

}

这是第一级第二级问题。

public class level1q2 extends ActionBarActivity {

private EditText mans1;
private TextView mcount;
int sum;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_level1q2);

    TextView textView = (TextView)findViewById(R.id.count);
    Intent intent = getIntent();
    int count = intent.getIntExtra("mycount", 0);
     textView.setText(count);}


    public void Onclick(View view)
    {
        mans1 = (EditText) findViewById(R.id.ans1);
        mcount = (TextView) findViewById(R.id.count);
        double answer = Double.parseDouble(mans1.getText().toString());


        if (answer == (15-3)) {
            Toast.makeText(level1q2.this, "الإجابة صحيحة", Toast.LENGTH_LONG).show();
            int count = getIntent().getIntExtra("mycount", 0);
            mcount.setText(count++);

        } else {
            Toast.makeText(level1q2.this, "الإجابة خاطئة", Toast.LENGTH_LONG).show();
            int count = getIntent().getIntExtra("mycount", 0);
            mcount.setText(count);

        }
    }

public void buttonOnClickgo(View v) {

    Button next = (Button) v;
    startActivity(new Intent(getApplicationContext(), level1q3.class));


}

public void buttonOnClickBack(View v) {

    Button back = (Button) v;
    startActivity(new Intent(getApplicationContext(), Activity2.class));
}

}

我在这些类中做了一些更改,因为我想将count变量从第一个问题传递到第二个问题活动。

在我编辑它们之前它正在工作,但现在它显示“不幸停止”的消息..

请查看代码

调试后..

04:30:29.101    1075-1075/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb3b03ba8)
08-23 04:30:29.121    1075-1075/com.mainuser.math.passgrade4.passgrade4 E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.mainuser.math.passgrade4.passgrade4, PID: 1075
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mainuser.math.passgrade4.passgrade4/com.mainuser.math.passgrade4.passgrade4.level1}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
            at com.mainuser.math.passgrade4.passgrade4.level1.onCreate(level1.java:34)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
08-23 04:30:37.051    1075-1075/com.mainuser.math.passgrade4.passgrade4 I/Process﹕ Sending signal. PID: 1075 SIG: 9
08-23 04:30:38.061    1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
08-23 04:30:38.061    1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11347: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
08-23 04:30:38.061    1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
08-23 04:30:38.061    1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
08-23 04:30:38.071    1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11353: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
08-23 04:30:38.071    1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
08-23 04:30:38.071    1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
08-23 04:30:38.071    1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 9041: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
08-23 04:30:38.071    1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
08-23 04:30:38.101    1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
08-23 04:30:38.101    1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 366: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
08-23 04:30:38.101    1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-23 04:30:38.111    1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
08-23 04:30:38.111    1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 388: Landroid/content/res/TypedArray;.getType (I)I
08-23 04:30:38.111    1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-23 04:30:38.591    1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ GC_FOR_ALLOC freed 125K, 7% free 2894K/3100K, paused 35ms, total 35ms

1 个答案:

答案 0 :(得分:1)

问题正是你的例外所说的:

<script src="http://www.iclubz.com/js/jquery.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

<script src="http://www.iclubz.com/js/readmore.min.js"></script>

<script src="http://www.iclubz.com/js/chosen.jquery.js"></script>

<script src="http://www.iclubz.com/js/jquery.validate.min.js"></script>

<script src="http://www.iclubz.com/js/fileinput.min.js"></script>

您的按钮是一个ImageButton,但您尝试将其强制转换为Button(不是ImageButton的超类)。