显示器上有错误信息:
07-20 17:00:05.234 17194-17194/com.example.champion.courtcounter E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.champion.courtcounter/com.example.champion.courtcounter.MainActivity}: android.view.InflateException: Binary XML file line #69: Error inflating class null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2129)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2154)
at android.app.ActivityThread.access$700(ActivityThread.java:146)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1260)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4949)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #69: Error inflating class null
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.champion.courtcounter.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5185)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2154)
at android.app.ActivityThread.access$700(ActivityThread.java:146)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1260)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4949)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:681)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.champion.courtcounter.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5185)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2154)
at android.app.ActivityThread.access$700(ActivityThread.java:146)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1260)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4949)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
at dalvik.system.NativeStart.main(Native Method)
有我的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:padding="16dp"
android:text="Team A"
android:textColor="#616161"
android:textSize="14sp" />
<TextView
android:id="@+id/team_a_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:paddingBottom="24dp"
android:text="0"
android:textColor="#000000"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="points3"
android:text="+3 points" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:onClick="points2"
android:text="+2 points" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="point"
android:text="free throw" />
</LinearLayout>
<view
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:background="@android:color/darker_gray" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:padding="16dp"
android:text="Team B"
android:textColor="#616161"
android:textSize="14sp" />
<TextView
android:id="@+id/team_b_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:paddingBottom="24dp"
android:text="0"
android:textColor="#000000"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="points3B"
android:text="+3 points" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:onClick="points2B"
android:text="+2 points" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="pointB"
android:text="free throw" />
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
android:onClick="reset"
android:text="reset" />
</RelativeLayout>
有我的java代码:
package com.example.champion.courtcounter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.example.champion.courtcounter.R;
public class MainActivity extends AppCompatActivity {
int numA=0;
int numB=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void displayForTeamA(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_a_score);
scoreView.setText(String.valueOf(score));
}
public void points3(View view) {
numA = numA + 3;
displayForTeamA(numA);
}
public void points2(View view) {
numA = numA + 2;
displayForTeamA(numA);
}
public void point(View view) {
numA = numA + 1;
displayForTeamA(numA);
}
public void displayForTeamB(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_b_score);
scoreView.setText(String.valueOf(score));
}
public void points3B(View view) {
numB = numB + 3;
displayForTeamB(numB);
}
public void points2B(View view) {
numB = numB + 2;
displayForTeamB(numB);
}
public void pointB(View view) {
numB = numB + 1;
displayForTeamB(numB);
}
public void reset(View view) {
numB = 0;
displayForTeamB(numB);
numA = 0;
displayForTeamA(numA);
}
}
我甚至无法打开它。当我试图打开它时说:“不幸的是,Court Counter(我的应用程序的名称)已停止。 谢谢你的帮助。
答案 0 :(得分:0)
<view
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:background="@android:color/darker_gray" />
使用view
View