这是我的MainActivity.java文件:
package com.example.kushalpc.app1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText userNameEditText;
EditText passwordEditText;
TextView userNameTextView;
TextView passwordTextView;
TextView resultTextView;
CharSequence resultLoginSuccess = "Login Successful";
CharSequence resultLoginFailed = "Login Failed";
TextView createAccount;
Button loginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userNameTextView = (TextView) findViewById(R.id.userName);
passwordTextView = (TextView) findViewById(R.id.password);
userNameEditText = (EditText) findViewById(R.id.userNameValue);
passwordEditText = (EditText) findViewById(R.id.passwordValue);
resultTextView = (TextView) findViewById(R.id.resultTextView);
loginButton = (Button) findViewById(R.id.loginButton);
createAccount = (TextView) findViewById(R.id.createAccountTextView);
createAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
setContentView(R.layout.registration);
}
});
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(userNameEditText.getText().toString().equals("admin")
&& passwordEditText.getText().toString().equals("1234"))
resultTextView.setText(resultLoginSuccess);
else
resultTextView.setText(resultLoginFailed);
}
});
}
}
这是我的RegistrationForm.java文件
package com.example.kushalpc.app1;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class RegistrationForm extends AppCompatActivity{
Button goButton;
TextView errorTextView;
CharSequence c = "HEY";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
goButton = (Button) findViewById(R.id.goButton);
errorTextView = (TextView) findViewById(R.id.emptyErrorTextView);
goButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
System.out.println(c);
}
});
}
}
ActivityMain.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/userName"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/userName"
/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/userNameValue"
android:layout_toEndOf="@+id/userName"
android:textSize="14sp"
android:textStyle="bold"
android:layout_marginLeft="10dp"
/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/passwordValue"
android:layout_below="@id/userName"
android:layout_toEndOf="@+id/password"
android:textSize="14sp"
android:textStyle="bold"
android:layout_marginStart="15dp"
android:layout_marginTop="32dp"
android:inputType="textPassword"
/>
<TextView
android:layout_marginTop="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/password"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@id/userName"
android:id="@id/password"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/passwordValue"
android:id="@+id/loginButton"
android:text="@string/login"
android:layout_marginTop="20dp"
/>
<TextView
android:text="@string/createAccount"
android:id="@+id/createAccountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_centerHorizontal="true"
android:textStyle="italic"
android:textColor="#000000"
android:layout_below="@id/loginButton"
android:clickable="true"
/>
<TextView
android:layout_marginTop="140dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:id="@+id/resultTextView"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@id/password"
/>
</RelativeLayout>
Registration.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_marginStart="40dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="30dp"
tools:Context="com.example.kushalpc.app1.RegistrationForm">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/name"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lastName"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/lastName"
android:layout_below="@id/name"
android:layout_marginTop="40dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dateOfBirth"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/dateOfBirth"
android:layout_below="@id/lastName"
android:layout_marginTop="40dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/createPassword"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/createPassword"
android:layout_below="@id/dateOfBirth"
android:layout_marginTop="40dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/conformPassword"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/conformPassword"
android:layout_below="@id/createPassword"
android:layout_marginTop="40dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/createUserName"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/createUserName"
android:layout_below="@id/conformPassword"
android:layout_marginTop="40dp"
/>
<EditText
android:layout_marginTop="-10dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/nameValue"
android:textSize="14sp"
android:textStyle="bold"
android:layout_alignParentEnd="true"
/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/lastNameValue"
android:textSize="14sp"
android:textStyle="bold"
android:layout_below="@id/name"
android:layout_marginTop="30dp"
android:layout_alignParentEnd="true"
/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/dateOfBirthValue"
android:inputType="date"
android:textSize="14sp"
android:textStyle="bold"
android:layout_below="@id/lastName"
android:layout_marginTop="30dp"
android:layout_alignParentEnd="true"
/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/createPasswordValue"
android:textSize="14sp"
android:textStyle="bold"
android:layout_below="@id/dateOfBirth"
android:layout_marginTop="30dp"
android:layout_alignParentEnd="true"
/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/conformPasswordValue"
android:textSize="14sp"
android:textStyle="bold"
android:layout_below="@id/createPassword"
android:layout_marginTop="30dp"
android:layout_alignParentEnd="true"
/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/createUserNameValue"
android:textSize="14sp"
android:textStyle="bold"
android:layout_below="@id/conformPassword"
android:layout_marginTop="30dp"
android:layout_alignParentEnd="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/createUserNameValue"
android:layout_alignEnd="@id/createUserNameValue"
android:id="@+id/goButton"
android:text="@string/go"
android:layout_marginTop="15dp"
/>
<!--
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/createUserName"
android:layout_alignStart="@id/createUserName"
android:id="@+id/exitButton"
android:text="@string/exit"
android:layout_marginTop="20dp"
/>-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_below="@+id/goButton"
android:textStyle="bold"
android:text="sample"
android:textColor="#000000"
android:id="@+id/emptyErrorTextView"
/>
<!--android:layout_below="@id/exitButton"
android:layout_marginTop="40dp"
-->
</RelativeLayout>
当我运行我的代码时,以下是红色的日志cat错误:
07-08 11:44:38.704 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.os.PersistableBundle&#39;,引用自 方法com.example.kushalpc.app1.MainActivity.access $ super
07-08 11:44:38.704 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.os.PersistableBundle&#39;,引用自 方法com.example.kushalpc.app1.MainActivity.access $ super
-07-08 11:44:38.704 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.media.session.MediaController&#39;, 从方法中引用 com.example.kushalpc.app1.MainActivity.access $超
-07-08 11:44:38.712 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.widget.Toolbar&#39;,从方法引用 com.example.kushalpc.app1.MainActivity.access $超
-07-08 11:44:38.712 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.app.ActivityManager $ TaskDescription&#39;,引用方法&gt ; com.example.kushalpc.app1.MainActivity.access $超
-07-08 11:44:38.720 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.app.SharedElementCallback&#39;,引用 来自方法com.example.kushalpc.app1.MainActivity.access $ super
-07-08 11:44:38.720 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.os.PersistableBundle&#39;,引用自 方法com.example.kushalpc.app1.MainActivity.access $ super
-07-08 11:44:38.720 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.app.SharedElementCallback&#39;,从方法&gt; com引用.example.kushalpc.app1.MainActivity.access $超
-07-08 11:44:38.736 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.app.assist.AssistContent&#39;,从方法引用 com.example.kushalpc.app1.MainActivity.access $超
-07-08 11:44:38.736 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.view.SearchEvent&#39;,从方法引用 com.example.kushalpc.app1.MainActivity.access $超
-07-08 11:44:38.744 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.os.PersistableBundle&#39;,从方法引用 com.example.kushalpc.app1.MainActivity.access $超
-07-08 11:44:47.180 1578-1578 / com.example.kushalpc.app1 E / OpenGLRenderer:从GradienCache获取MAX_TEXTURE_SIZE 07-08 11:44:47.188 1578-1578 / com.example.kushalpc.app1 E / OpenGLRenderer: MAX_TEXTURE_SIZE:8192 07-08 11:44:47.244 1578-1578 / com.example.kushalpc.app1 E / OpenGLRenderer:获取 来自Caches :: initConstraints()07-08 11:44:47.244的MAX_TEXTURE_SIZE 1578-1578 / com.example.kushalpc.app1 E / OpenGLRenderer: MAX_TEXTURE_SIZE:8192
-07-08 11:44:47.336 1578-1578 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.graphics.drawable.RippleDrawable&#39;, 从方法中引用 android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
- 07-08 11:49:31.865 5587-5587 / com.example.kushalpc.app1 E / OpenGLRenderer:从GradienCache获取MAX_TEXTURE_SIZE 07-08 11:49:31.869 5587-5587 / com.example.kushalpc.app1 E / OpenGLRenderer: MAX_TEXTURE_SIZE:8192 07-08 11:49:31.885 5587-5587 / com.example.kushalpc.app1 E / OpenGLRenderer:获取 来自Caches :: initConstraints()07-08 11:49:31.893的MAX_TEXTURE_SIZE 5587-5587 / com.example.kushalpc.app1 E / OpenGLRenderer: MAX_TEXTURE_SIZE:8192
-07-08 11:49:31.917 5587-5587 / com.example.kushalpc.app1 E / dalvikvm:找不到类&#39; android.graphics.drawable.RippleDrawable&#39;, 从方法中引用 android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
答案 0 :(得分:1)
只需在build.gradle(Module:app)文件defaultConfig部分添加multiDexEnabled,然后重建项目。它将删除所有错误,但你不会使用21以下的即时运行。
示例如下
build.gradle中的(模块:app) 。 。 。 defaultConfig { ...... multiDexEnabled是的 } 。 。