Java AndroidManifes xml存在问题。App force在跑步时关闭
嘿,伙计们,我对安卓系统还很陌生。我认为第一个应用程序的好主意应该是一个计算器。我完全创建了那个应用程序,它可以正确安装和编译。但当我在我的设备上运行它时,它会强制关闭。我想我的AndroidManifest.xml文件中可能有问题,但我不知道是什么问题 这是may java代码:Java AndroidManifes xml存在问题。App force在跑步时关闭,java,android,Java,Android,嘿,伙计们,我对安卓系统还很陌生。我认为第一个应用程序的好主意应该是一个计算器。我完全创建了那个应用程序,它可以正确安装和编译。但当我在我的设备上运行它时,它会强制关闭。我想我的AndroidManifest.xml文件中可能有问题,但我不知道是什么问题 这是may java代码: import android.os.Bundle; import android.app.Activity; import android.text.Editable; import android.view.Men
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.awesomeapps.misael.simplecalculator.R;
public class MainActivity extends Activity implements View.OnClickListener{
Button one, two, three, four, five, six, seven, eight, nine, zero, add, sub, mul, div, cancel, equal;
EditText disp;
int op1;
int op2;
String optr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
one = (Button) findViewById(R.id.one);
two = (Button) findViewById(R.id.two);
three = (Button) findViewById(R.id.three);
four = (Button) findViewById(R.id.four);
five = (Button) findViewById(R.id.five);
six = (Button) findViewById(R.id.six);
seven = (Button) findViewById(R.id.seven);
eight = (Button) findViewById(R.id.eight);
nine = (Button) findViewById(R.id.nine);
zero = (Button) findViewById(R.id.zero);
add = (Button) findViewById(R.id.add);
sub = (Button) findViewById(R.id.sub);
mul = (Button) findViewById(R.id.mul);
div = (Button) findViewById(R.id.div);
cancel = (Button) findViewById(R.id.cancel);
equal = (Button) findViewById(R.id.equal);
disp = (EditText) findViewById(R.id.editText);
try {
one.setOnClickListener(this);
two.setOnClickListener(this);
three.setOnClickListener(this);
four.setOnClickListener(this);
five.setOnClickListener(this);
six.setOnClickListener(this);
seven.setOnClickListener(this);
eight.setOnClickListener(this);
nine.setOnClickListener(this);
zero.setOnClickListener(this);
cancel.setOnClickListener(this);
add.setOnClickListener(this);
sub.setOnClickListener(this);
mul.setOnClickListener(this);
div.setOnClickListener(this);
equal.setOnClickListener(this);
} catch (Exception e) {
}
}
public void operation() {
if (optr.equals("+")) {
op2 = Integer.parseInt(disp.getText().toString());
disp.setText("");
op1 = op1 + op2;
disp.setText("Result: " + Integer.toString(op1));
} else if (optr.equals("-")) {
op2 = Integer.parseInt(disp.getText().toString());
disp.setText("");
op1 = op1 - op2;
disp.setText("Result" + Integer.toString(op1));
} else if (optr.equals("*")) {
op2 = Integer.parseInt(disp.getText().toString());
disp.setText("");
op1 = op1 * op2;
disp.setText("Result" + Integer.toString(op1));
} else if (optr.equals("/")) {
op2 = Integer.parseInt(disp.getText().toString());
disp.setText("");
op1 = op1 / op2;
disp.setText("Result" + Integer.toString(op1));
}
}
@Override
public void onClick(View arg0) {
Editable str = disp.getText();
switch (arg0.getId()) {
case R.id.one:
if (op2 != 0) {
op2 = 0;
disp.setText("");
}
str = str.append(two.getText());
disp.setText(str);
break;
case R.id.two:
if (op2 != 0) {
op2 = 0;
}
str = str.append(two.getText());
disp.setText(str);
case R.id.three:
if (op2 != 0) {
op2 = 0;
}
str = str.append(three.getText());
disp.setText(str);
break;
case R.id.four:
if (op2 != 0) {
op2 = 0;
}
str = str.append(four.getText());
disp.setText(str);
break;
case R.id.five:
if (op2 != 0) {
op2 = 0;
}
str = str.append(five.getText());
disp.setText(str);
break;
case R.id.six:
if (op2 != 0) {
op2 = 0;
}
str = str.append(six.getText());
disp.setText(str);
break;
case R.id.seven:
if (op2 != 0) {
op2 = 0;
}
str = str.append(eight.getText());
disp.setText(str);
break;
case R.id.eight:
if (op2 != 0) {
op2 = 0;
}
str = str.append(nine.getText());
disp.setText(str);
break;
case R.id.nine:
if (op2 != 0) {
op2 = 0;
}
str = str.append(zero.getText());
disp.setText(str);
break;
case R.id.cancel:
op1 = 0;
op2 = 0;
disp.setText("");
disp.setHint("Perform Operation");
break;
case R.id.add:
optr = "+";
if (op1 == 0) {
op1 = Integer.parseInt(disp.getText().toString());
disp.setText("");
} else if (op2 != 0) {
op2 = 0;
disp.setText("");
} else {
op2 = Integer.parseInt(disp.getText().toString());
disp.setText("");
op1 = op1 + op2;
disp.setText("Result" + Integer.toString(op1));
}
break;
case R.id.sub:
optr = "-";
if (op1 == 0) {
op1 = Integer.parseInt(disp.getText().toString());
disp.setText("");
} else if (op2 != 0) {
op2 = 0;
disp.setText("");
} else {
op2 = Integer.parseInt(disp.getText().toString());
disp.setText("");
op1 = op1 - op2;
disp.setText("Result" + Integer.toString(op1));
}
break;
case R.id.mul:
optr = "*";
if (op1 == 0) {
op1 = Integer.parseInt(disp.getText().toString());
disp.setText("");
} else if (op2 != 0) {
op2 = 0;
disp.setText("");
} else {
op2 = Integer.parseInt(disp.getText().toString());
disp.setText("");
op1 = op1 * op2;
disp.setText("Result" + Integer.toString(op1));
}
break;
case R.id.div:
optr = "/";
if (op1 == 0) {
op1 = Integer.parseInt(disp.getText().toString());
disp.setText("");
} else if (op2 != 0) {
op2 = 0;
disp.setText("");
} else {
op2 = Integer.parseInt(disp.getText().toString());
disp.setText("");
op1 = op1 / op2;
disp.setText("Result" + Integer.toString(op1));
}
break;
case R.id.equal:
if (optr.equals(null)) {
if (op2 != 0) {
if (optr.equals("+")) {
disp.setText("");
/*op1 = op1+op2;*/
disp.setText("Result:" + Integer.toString(op1));
} else if (optr.equals("-")) {
disp.setText("");/*
op1 = op1 - op2;*/
disp.setText("Result" + Integer.toString(op1));
} else if (optr.equals("*")) {
disp.setText("");/*
op1 = op1*op2;*/
disp.setText("Result" + Integer.toString(op1));
} else if (optr.equals("/")) {
disp.setText("");/*
op1=op1/op2;*/
disp.setText("Result" + Integer.toString(op1));
}
} else {
operation();
}
}
break;
}
}
}
这是我的AndroidManifest xml文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.awesomeapps.misael.simplecalculator">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
如果有人能告诉我在我的java代码或android清单xml文件中修复什么,请提供帮助。或者是完全不同的东西
任何帮助都将是了不起的,非常感谢!谢谢!:) 如果要在项目中启用多索引,只需转到gradle.builder即可 并将此添加到您的dependencie中
dependencies {
compile 'com.android.support:multidex:1.0.0'}
那么你必须加上
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true}
然后打开一个类并将其extandtoapplication如果您的应用程序使用extendtoapplication类,您可以重写oncrete()方法并调用
//add this code into your application class
public class MyApplication extends Application {
// public Context context;
@Override
public void onCreate( ) {
super.onCreate();
}
}
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}
启用多索引
最后添加到您的清单中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name=".MyApplication"">
...
</application>
</manifest>
在MainActivity课程顶部添加以下行:
package com.awesomeapps.misael.simplecalculator;
在此之后,请清理并重建您的项目。我已尝试运行您的代码,并将所有内容粘贴到新项目中。我接下来做的是:
1) 删除这个
import com.awesomeapps.misael.simplecalculator.R;
2) 已将我的包导入MainActivity.java的第一行(我想这是您的情况)
我还没动清单文件。然后它运行起来没有任何错误
但是,我应该提到,在您的代码中有很多bug。至少,它没有显示结果,一些数字按钮在按下时输入了不正确的值。运行代码并修复bug。最后,如果你在布局中加入一些文本视图来解释如何使用计算器,那就太好了。快乐编码:)将程序包名称添加到MainActivity
package com.awesomeapps.misael.simplecalculator;
删除此行import com.awesomeapps.misael.simplecalculator.R代码>
删除生成文件夹
清理并重建项目。希望它能解决您的问题。没有包com.awesomeapps.misael.simplecalculator代码>在活动类中。包的名称是什么?我猜你放了不正确的包。添加包并删除import com.awesomeapps.misael.simplecalculator.R代码>清理项目>重新启动IDE>并重建项目我也会遇到同样的错误(classNotFoundException),添加此代码,工作正常我正在使用Android studio我真的不知道去哪里做更改我尝试了你所做的,它说Oacker不存在。@业余程序员你是否在最上面包含了包名?它应该在MainActivity.javaI的第一行,在我的包行和XML文件中的活动名称行中有一个巨大的输入错误,但我终于做到了,它工作了!现在我知道我有很多bug需要修复,哈哈,谢谢你的帮助我发现在我的包名行和XML文件中有大量的打字错误,谢谢你们的帮助!现在要修复一些bug lol:)@业余程序员它现在工作正常了吗?你成功修复了所有的bug吗?
package com.awesomeapps.misael.simplecalculator;
package com.awesomeapps.misael.simplecalculator;