您好,感谢您阅读本文。
我正在尝试构建一个除分数之外的测量应用程序,以及目标尝试和犯规的分数。显然Java不同意我的看法。
这是让我无言以对的错误:
* * JAVA代码**
package com.example.android.courtcounter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.example.android.soccercounter.R;
public class MainActivity extends AppCompatActivity {
int scoreTeamA = 0;
int scoreTeamB = 0;
int FoulForTeamA = 0;
int FoulForTeamB = 0;
int ShotOnGoalForTeamA = 0;
int ShotOnGoalForTeamB = 0;
/**
* Displays the given score for Team A.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* Displays the given score for Team A.
*/
public void displayForTeamA(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_a_score);
scoreView.setText(String.valueOf(score));
}
/**
* 1.0-Displays the FOUL score for Team A.
*/
public void displayFoulScoreForTeamA(int foulForTeamA) {
TextView scoreView = (TextView) findViewById(R.id.team_a_foul_score);
scoreView.setText(String.valueOf(foulForTeamA));
}
/**
* 1.0-Displays the goal attempt score for Team A.
*/
public void displayGoalAttemptForTeamA(int shotOnGoalForTeamA) {
TextView scoreView = (TextView) findViewById(R.id.team_a_goal_attempt_score);
scoreView.setText(String.valueOf(shotOnGoalForTeamA));
}
/**
* Displays the given score for Team B.
*/
public void displayForTeamB(int foulForTeamB) {
TextView scoreView = (TextView) findViewById(R.id.team_b_score);
scoreView.setText(String.valueOf(foulForTeamB));
}
/**
* 1.0-Displays the given FOUL score for Team B.
* Probably i have to modify the int score to int foul score,but I haven't located.
*/
public void displayFoulScoreForTeamB(int foulForTeamB) {
TextView scoreView = (TextView) findViewById(R.id.team_b_foul_score);
scoreView.setText(String.valueOf(foulForTeamB));
}
/**
* 1.0-Displays the goal attempt score for Team B.
*/
public void displayGoalAttemptForTeamB(int shotOnGoalForTeamB) {
TextView scoreView = (TextView) findViewById(R.id.team_b_goal_attempt_score);
scoreView.setText(String.valueOf(shotOnGoalForTeamB));
}
/**
* Increase the score for Team A by 1 point.
*/
public void addOneForTeamA(View v) {
scoreTeamA=scoreTeamA + 1;
displayForTeamA(scoreTeamA);
}
/**
* 1.0-Increase the FOUL score for Team A by 1 point.
* Maybe I should modify this whole addFoul,i still do not get the add part,is it mandatory?
*/
public void addFoulForTeamA(View v) {
FoulForTeamA=FoulForTeamA + 1;
displayForTeamA(FoulForTeamA);
}
/**
* Increase the score for Team B by 1 point.
*/
public void addOneForTeamB(View v) {
scoreTeamB=scoreTeamB + 1;
displayForTeamB(scoreTeamB);
}
/**
* 1.0-Increase the FOUL score for Team B by 1 point.
* Maybe I should modify this whole addFoul,i still do not get the add part,is it mandatory?
*/
public void addFoulForTeamB(View v) {
FoulForTeamB=FoulForTeamB + 1;
displayForTeamB(FoulForTeamB);
}
/*
* Increase the GOAL ATTEMPT score for Team A by 1 point.
*/
public void addGoalAttemptForTeamA(View v) {
ShotOnGoalForTeamA=ShotOnGoalForTeamA + 1;
displayForTeamA(ShotOnGoalForTeamA);
}
/**
* Increase the GOAL ATTEMPT score for Team B by 1 point.
*/
public void addGoalAttemptForTeamB(View v) {
ShotOnGoalForTeamB=ShotOnGoalForTeamB + 3;
displayForTeamB(ShotOnGoalForTeamB);
}
/**
* *This will (hopefully) reset the values of the scores of both teams to 0
*/
public void resetScore(View v) {
scoreTeamA=0;
scoreTeamB=0;
FoulForTeamA = 0;
FoulForTeamB = 0;
ShotOnGoalForTeamA = 0;
ShotOnGoalForTeamB = 0;
displayForTeamA(scoreTeamA);
displayForTeamB(scoreTeamB);
displayFoulScoreForTeamA(FoulForTeamA);
displayFoulScoreForTeamB(FoulForTeamB);
displayGoalAttemptForTeamA(ShotOnGoalForTeamA);
displayFoulScoreForTeamB(ShotOnGoalForTeamB);
}
}
>
> 我现在将添加实际错误:
01-07 11:47:14.420 26936-26936/com.example.android.soccercounter E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.soccercounter, PID: 26936
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.soccercounter/com.example.android.soccercounter.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.android.soccercounter.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.soccercounter-2/base.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.android.soccercounter-2/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.soccercounter.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.soccercounter-2/base.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.android.soccercounter-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.android.soccercounter-2/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
以及现在的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="Team A" />
<TextView
android:id="@+id/team_a_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="0"
android:textSize="56sp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:onClick="addOneForTeamA"
android:text="Add a Goal!"
android:textColor="@android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_height="wrap_content"
android:text="Fouls comitted :"
android:textSize="14sp"
android:textColor="@color/colorPrimaryDark"/>
<TextView
android:id="@+id/team_a_foul_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="0"
android:textSize="26sp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:onClick="addFoulForTeamA"
android:text="Add a foul"
android:textColor="@android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_marginLeft="16dp"
android:layout_height="wrap_content"
android:text="Goal Attempts:"
android:textSize="14sp"
android:textColor="@color/colorPrimaryDark"/>
<TextView
android:id="@+id/team_a_goal_attempt_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="0"
android:textSize="26sp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:onClick="addShotOnGoalForTeamA"
android:text="Add a Shot on Goal"
android:textColor="@android:color/white"/>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_dark">
</View>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="Team B" />
<TextView
android:id="@+id/team_b_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="0"
android:textSize="56sp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:onClick="addOneForTeamB"
android:text="Add a Goal!"
android:textColor="@android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_marginLeft="16dp"
android:layout_height="wrap_content"
android:text="Fouls comitted :"
android:textSize="14sp"
android:textColor="@color/colorPrimaryDark"/>
<TextView
android:id="@+id/team_b_foul_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="0"
android:textSize="26sp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:onClick="addFoulForTeamB"
android:text="Add a foul"
android:textColor="@android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_marginLeft="16dp"
android:layout_height="wrap_content"
android:text="Goal Attempts:"
android:textSize="14sp"
android:textColor="@color/colorPrimaryDark"/>
<TextView
android:id="@+id/team_b_goal_attempt_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="0"
android:textSize="26sp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:onClick="addShotOnGoalForTeamB"
android:text="Add a Shot on Goal"
android:textColor="@android:color/white"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Referee"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Stadium"
android:textSize="18sp"
android:textColor="@android:color/black"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="140dp"
android:layout_marginLeft="140dp"
android:onClick="resetScore"
android:text="RESET score "
android:textColor="@android:color/white"
android:layout_marginBottom="8dp"/>
</LinearLayout>
答案 0 :(得分:0)
我认为你提供的文件名不是由它搜索的,所以apk文件通过异常所以使用filehandler或导入文件