| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6830 人关注过本帖
标题:这个程序我在华为mate8里面点击按钮会出现闪退,求助,多谢
只看楼主 加入收藏
the_second
Rank: 2
等 级:论坛游民
帖 子:115
专家分:80
注 册:2015-9-13
结帖率:78.95%
收藏
 问题点数:0 回复次数:7 
这个程序我在华为mate8里面点击按钮会出现闪退,求助,多谢
package com.example.administrator.practice_clock;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button btGetMoney;
    private Button pic;
    private Button btnLoseMoney;
    private TextView tvGetMoney;
    private EditText etGoalMoney;
    private ImageView p;
    private int[] images = {
        R.drawable.a,
        R.drawable.b,
        R.drawable.c,
        R.drawable.e,
        R.drawable.f
    };
    private int imageIndex = 0;
    private int money = 10;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btGetMoney = (Button) findViewById(R.id.btnGetMoney);
        tvGetMoney = (TextView) findViewById(R.id.tvGetMoney);
        btnLoseMoney = (Button) findViewById(R.id.btnLoseMoney);
        pic = (Button) findViewById(R.id.pic);
        etGoalMoney = (EditText)findViewById(R.id.etGoalMoney);
        p = (ImageView)findViewById(R.id.p);
        btGetMoney.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View arg0)
            {
                String s = etGoalMoney.getText().toString().trim();
                int iMoney = Integer.parseInt(s);
                if(iMoney == money)
                {
                    Toast.makeText(MainActivity.this,"完成目标",Toast.LENGTH_SHORT).show();
                }
                else
                {
                    money++;
                    tvGetMoney.setText("哈哈,我通过点击轻易赚了"+money+"元");
                }

            }
        });
        btnLoseMoney.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {

                if(money == 0)
                {
                    Toast.makeText(MainActivity.this,"我现在是穷光蛋了",Toast.LENGTH_SHORT).show();
                }
                else
                {
                    money--;
                    tvGetMoney.setText("哈哈,我通过点击轻易赚了"+money+"元");
                }
            }
        });
        pic.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View arg0)
            {
                imageIndex++;
                if(imageIndex>4)
                {
                    imageIndex = 0;
                }
                p.setImageResource(images[imageIndex]);
            }
        });
    }

}
搜索更多相关主题的帖子: package import 华为 
2016-05-18 13:19
the_second
Rank: 2
等 级:论坛游民
帖 子:115
专家分:80
注 册:2015-9-13
收藏
得分:0 
上面的代码是我的java文件下MainActivity的
还有手机的系统是安卓6.0的,但是我电脑里面SDK包,安卓6.0的安装了的
2016-05-18 13:20
the_second
Rank: 2
等 级:论坛游民
帖 子:115
专家分:80
注 册:2015-9-13
收藏
得分:0 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.
    xmlns:app="http://schemas.
    xmlns:tools="http://schemas.
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#5eff00"
    tools:context="com.example.administrator.practice_clock.MainActivity">
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/etGoalMoney"
        android:hint="the you want to earn"
        android:layout_margin="10px"
        android:inputType="none"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10px"
        android:background="#0004ff"
        android:text="点我一次赚一元"
        android:id="@+id/btnGetMoney"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10px"
        android:background="#ff0000"
        android:text="点击一次损失一元"
        android:id="@+id/btnLoseMoney"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10px"
        android:background="#ff00ff"
        android:text="picture"
        android:id="@+id/pic"/>
    <TextView
        android:text="哈哈我通过点击轻易赚了..."
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#00d9ff"
        android:textSize="20dp"
        android:layout_margin="10px"
        android:id="@+id/tvGetMoney"/>
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/p"
        android:src="@drawable/a"/>
</LinearLayout>
2016-05-18 13:21
the_second
Rank: 2
等 级:论坛游民
帖 子:115
专家分:80
注 册:2015-9-13
收藏
得分:0 
这是我的布局代码
求助,万分感谢
2016-05-18 13:21
aijiao0624
Rank: 2
等 级:论坛游民
威 望:3
帖 子:27
专家分:65
注 册:2016-7-19
收藏
得分:0 
去看看logcat的错误信息
2016-07-21 14:41
wangdeyou86
Rank: 2
等 级:论坛游民
威 望:1
帖 子:33
专家分:39
注 册:2009-3-22
收藏
得分:0 
大概是“s”没成功转换成整型数据造成的
2017-04-27 07:25
佐德
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-1-3
收藏
得分:0 
先搞个APP log 看一下
2017-10-18 22:31
ADust、
Rank: 2
等 级:论坛游民
帖 子:21
专家分:57
注 册:2013-1-10
收藏
得分:0 
String s = etGoalMoney.getText().toString().trim();
 int iMoney = Integer.parseInt(s);

输入框输入为空的时候,点击闪退,这个s为" ",转型出错了,还有Edittext如果没有限制输入类型为number的话,转型也会出错
2017-11-03 14:15
快速回复:这个程序我在华为mate8里面点击按钮会出现闪退,求助,多谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016845 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved