应用程式因「不幸的是年龄计算器专业版已停止运作」而当机,但编译时没有错误

时间:2019-02-05 08:57:21

标签: android

我的app agecalulator pro在playstore上,并且在更新后崩溃了: https://play.google.com/store/apps/details?id=com.singularity.agecalculatorpro

构建APK甚至运行应用程序时都没有错误。

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.singularity.agecalculatorpro">

    <application
        android:allowBackup="true"
        android:icon="@drawable/calci"
        android:roundIcon="@drawable/calci"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.google.android.gms.ads.ca-app-pub-xxxxxxxxxxxx"
            android:value="[ca-app-pub-xxxxxxxxxxxxx]"/>
        <activity android:name="com.singularity.agecalculatorpro.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

主要活动文件:

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

Button btn1;
EditText age;
TextView result;
private AdView mAdView;
private InterstitialAd mInterstitialAd;


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

        MobileAds.initialize(this,
                "ca-app-pub-xxxxxxxxxxx");

        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxx");
        mInterstitialAd.loadAd(new AdRequest.Builder().build());

        btn1 = (Button) findViewById(R.id.btn1);
        age = (EditText) findViewById(R.id.age);
        result = (TextView) findViewById(R.id.result);
        btn1.setOnClickListener(this);


    }

    @Override
    public void onClick(View v)
    {
        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {
            Log.d("TAG", "The interstitial wasn't loaded yet.");
        }
    String Input_year = age.getText().toString();
    result.setVisibility(View.VISIBLE);
    if(Integer.parseInt(Input_year) < 2017)
    {
        Calendar calendar = Calendar.getInstance();
        int current_year = calendar.get(calendar.YEAR);
        int current_age = current_year - Integer.parseInt(Input_year);
        result.setText("Your Age is: " + current_age);
    }
    else
    {
        result.setText("Please Enter Correct Year");
    }
    }
}

Activity_Main.XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/one"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/adView"
        android:paddingBottom="10dp"
        android:layout_centerHorizontal="true"
        android:text="Calculate Age" />

    <EditText
        android:id="@+id/age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:hint="Enter your birth year"
        android:layout_marginTop="60dp"
        android:ems="10"
        android:inputType="number"
        android:maxLength="4"

        />

    <TextView
        android:id="@+id/result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/age"
        android:layout_marginTop="40dp"
        android:text="TextView"
        android:textSize="40dp"
        android:layout_centerHorizontal="true"
        android:visibility="invisible" />

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-xxxxxxx">
    </com.google.android.gms.ads.AdView>


</RelativeLayout>

此代码有什么问题?

1 个答案:

答案 0 :(得分:0)

我自己找到了答案。

罪犯:

implementation ("com.google.android.gms:play-services-ads:17.1.3")
            {
        exclude group: "com.android.support"
    }

解决方案: 替换为

implementation 'com.google.android.gms:play-services-ads:16.0.0'