【安卓开发】【Android Studio】项目构建(Build)时报错:Integer Overflow

一、问题描述

在安卓项目中,构建(Build)失败并报错:xxxxx Integer Overflow(整型溢出)。

二、相关代码

刚开始以为是某个整数(例如控件、java类)不匹配造成的,检查如下代码:

Java类:

java 复制代码
public class Video_Activity10 extends AppCompatActivity {
    private MediaPlayer mPlayer = null;
    private SurfaceView sfv_show;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video10);
        @SuppressLint({"MissingInflatedId", "LocalSuppress"}) SurfaceView sfv_show = findViewById(R.id.surface);
        SurfaceHolder surfaceHolder = sfv_show.getHolder();
        @SuppressLint({"MissingInflatedId", "LocalSuppress"}) Button btn_start = findViewById(R.id.btn1);
        @SuppressLint({"MissingInflatedId", "LocalSuppress"}) Button btn_pause = findViewById(R.id.btn2);
        @SuppressLint({"MissingInflatedId", "LocalSuppress"}) Button btn_stop = findViewById(R.id.btn3);
        mPlayer = MediaPlayer.create(Video_Activity10.this, R.raw.video_10);
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                Toast.makeText(Video_Activity10.this,"视频播放完毕",Toast.LENGTH_LONG).show();
            }
        });
        btn_start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPlayer.setDisplay(sfv_show.getHolder());
                mPlayer.start();
            }
        });
        btn_pause.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPlayer.pause();
            }
        });
        btn_stop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPlayer.stop();
            }
        });

    }
}

xml布局文件:

java 复制代码
<LinearLayout 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:orientation="vertical"
    tools:context=".Video_Activity10">

    <!--    视 频 主 体    -->
    <SurfaceView
        android:id="@+id/surface"
        android:layout_width="wrap_content"
        android:layout_height="480dp"
        android:layout_gravity="center_horizontal"
        android:keepScreenOn="true"/>

    <!--    播 放 按 钮    -->
    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/play"/>

    <!--    暂 停 按 钮    -->
    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/pause"/>

    <!--    停 止 按 钮    -->
    <Button
        android:id="@+id/btn3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/stop"/>

</LinearLayout>

没有问题。

之后,以为是内存限制过小导致,修改gradle.properties文件:

将这里的8000上调至10000:

java 复制代码
org.gradle.jvmargs=-Xmx8000m -Dfile.encoding=UTF-8

报错消失。

三、后续思考

However......之后,将上述的10000再改回8000,依旧没有报错。

可能是运行时出现的随机报错?

相关推荐
FungLeo8 分钟前
Flutter/Android Release 包连不上网?AndroidManifest INTERNET 权限排查实录
android·flutter
wWYy.2 小时前
Mysql:一行数据是怎么存储的?
android·数据库·mysql
漏刻有时9 小时前
PHP GeoJSON转PNG地图渲染程序开发笔记、源码解读、问题复盘与整改方案
android·笔记·php
-SOLO-10 小时前
解决VMware 显示比例被重置的问题
android
alexhilton11 小时前
探究Android Views、Flutter和Compose如何渲染你的UI
android·kotlin·android jetpack
Lesile14 小时前
Android:Hilt框架入门 · 在ViewUI和ComposeUI下的应用
android·android jetpack
用户4238162290714 小时前
Android 16 WebView 页面顶部挖孔/通知栏不能显示UI问题排查
android
weixin_7275356215 小时前
Loop 已死,Graph 新生:AI 工作流的范式革命
android·人工智能·rxjava
严同学正在努力16 小时前
从备份到恢复:我用 30 分钟恢复了误删的核心业务表
android·java·数据库·ai
梦想三三16 小时前
LangChain Output Parser 实战:从字符串到结构化数据的完整指南
android·服务器·langchain·github·uv