【发布时间】:2016-07-08 17:53:32
【问题描述】:
这是我的 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>
注册.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>
当我运行我的代码时,以下是红色的 log cat 错误:
07-08 11:44:38.704 1578-1578/com.example.kushalpc.app1 E/dalvikvm:找不到类 'android.os.PersistableBundle',引用自 方法 com.example.kushalpc.app1.MainActivity.access$super
07-08 11:44:38.704 1578-1578/com.example.kushalpc.app1 E/dalvikvm:找不到类 'android.os.PersistableBundle',引用自 方法 com.example.kushalpc.app1.MainActivity.access$super
-07-08 11:44:38.704 1578-1578/com.example.kushalpc.app1 E/dalvikvm: 找不到类 'android.media.session.MediaController', 从方法引用 com.example.kushalpc.app1.MainActivity.access$super
-07-08 11:44:38.712 1578-1578/com.example.kushalpc.app1 E/dalvikvm:找不到类 'android.widget.Toolbar',从方法中引用 com.example.kushalpc.app1.MainActivity.access$super
-07-08 11:44:38.712 1578-1578/com.example.kushalpc.app1 E/dalvikvm: 找不到类 'android.app.ActivityManager$TaskDescription',引用自方法 > com.example.kushalpc .app1.MainActivity.access$super
-07-08 11:44:38.720 1578-1578/com.example.kushalpc.app1 E/dalvikvm:找不到类 'android.app.SharedElementCallback',引用 来自方法 com.example.kushalpc.app1.MainActivity.access$super
-07-08 11:44:38.720 1578-1578/com.example.kushalpc.app1 E/dalvikvm:找不到类 'android.os.PersistableBundle',引用自 com.example.kushalpc.app1.MainActivity.access$super 方法
-07-08 11:44:38.720 1578-1578/com.example.kushalpc.app1 E/dalvikvm:找不到类 'android.app.SharedElementCallback',引用自方法 >com.example.kushalpc.app1 .MainActivity.access$super
-07-08 11:44:38.736 1578-1578/com.example.kushalpc.app1 E/dalvikvm:找不到类 'android.app.assist.AssistContent',从方法中引用 com.example.kushalpc.app1.MainActivity.access$super
-07-08 11:44:38.736 1578-1578/com.example.kushalpc.app1 E/dalvikvm:找不到类 'android.view.SearchEvent',从方法中引用 com.example.kushalpc.app1.MainActivity.access$super
-07-08 11:44:38.744 1578-1578/com.example.kushalpc.app1 E/dalvikvm:找不到类 'android.os.PersistableBundle',从方法中引用 com.example.kushalpc.app1.MainActivity.access$super
-07-08 11:44:47.180 1578-1578/com.example.kushalpc.app1 E/OpenGLRenderer:从 GradienCache 07-08 获取 MAX_TEXTURE_SIZE 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: 找不到类 'android.graphics.drawable.RippleDrawable', 从方法引用 android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
- 07-08 11:49:31.865 5587-5587/com.example.kushalpc.app1 E/OpenGLRenderer:从 GradienCache 07-08 获取 MAX_TEXTURE_SIZE 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: 找不到类 'android.graphics.drawable.RippleDrawable', 从方法引用 android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
【问题讨论】:
-
这些都不是问题。当您的代码(或库中的代码)引用设备上不存在的类或方法时,它们是完全正常的。
-
我该如何解决?我正在使用 geny motion google nexus 5 - 4.4.4- API 19
-
没有任何问题,仅基于这些消息。因此,没有什么可修复的。
-
gobutton onclicklistener 不工作!
-
@CommonsWare gobutton onclicklistener 不起作用!