标题:这个程序我在华为mate8里面点击按钮会出现闪退,求助,多谢
取消只看楼主
the_second
Rank: 2
等 级:论坛游民
帖 子:115
专家分:80
注 册:2015-9-13
结帖率:78.95%
 问题点数:0 回复次数:3 
这个程序我在华为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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-464958-1-1.html




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

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