我正在開發一個應用程序,它解碼了我放入文本字段的一串字符 。Android Studio ApplicationProblème正在運行
然後我按下按鈕,字符
我構建應用程序和字符串解碼,然後當我用我的手機 打開它,當我打開應用程序,並把一些caractere中的EditText 然後我推近解碼應用
這是我的代碼
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="decoder"
android:id="@+id/button1"
android:layout_below="@+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
MainActivity.java
package com.ghassensoussi7.decoder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Button button1;
private EditText editText1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button1);
editText1 = (EditText) findViewById(R.id.editText);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String [] strings =
editText1.getText().toString().split("/");
String s1 = strings[0];
String s2 = strings[1];
int s3 = Integer.parseInt(strings[2]);
String s4 = s2 + s3;
String s5 = strings[3];
//1ere caractere c'est une lettre
if(s1.equals("a") || s1.equals("b") || s1.equals("c")) {
Toast.makeText(MainActivity.this, "tu appartient a la
classe 1-1 ", Toast.LENGTH_LONG).show();
}
else
if (s1.equals("d") || s1.equals("e") || s1.equals("f"))
{
Toast.makeText(MainActivity.this, "tu appartient a
la classe 1-2 ", Toast.LENGTH_LONG).show();
}
else
if (s1.equals("g") || s1.equals("h") || s1.equals("i"))
{
Toast.makeText(MainActivity.this, "tu appartient a
la classe 1-3 ", Toast.LENGTH_LONG).show();
}
//2eme caractere c'est une lettre
if(s2.equals("a") || s2.equals("b") || s2.equals("c")) {
Toast.makeText(MainActivity.this, "tu appartient a la classe
2-1 ", Toast.LENGTH_LONG).show();
}
else
if(s2.equals("d") || s2.equals("e") || s2.equals("f")) {
Toast.makeText(MainActivity.this, "tu appartient a la classe
2-2 ", Toast.LENGTH_LONG).show();
}
//3eme caractere c'est un chiffre
switch (s3)
{
case 1:
Toast.makeText(MainActivity.this, "numero inferieur a la moyen", Toast.LENGTH_LONG).show();
break;
case 2:
Toast.makeText(MainActivity.this, "numero egal a la moyen", Toast.LENGTH_LONG).show();
break;
case 3:
Toast.makeText(MainActivity.this, "numero superieur a la moyen", Toast.LENGTH_LONG).show();
break;
}
//4eme et 5eme caractere
if(s4.equals("aa") || s2.equals("bb") || s2.equals("cc")) {
Toast.makeText(MainActivity.this, "tu appartient a la classe XX ", Toast.LENGTH_LONG).show();
}
else
if (s4.equals("dd") || s2.equals("ee") || s2.equals("ff")) {
Toast.makeText(MainActivity.this, "tu appartient a la classe YY ", Toast.LENGTH_LONG).show();
}
else
if (s4.equals("gg") || s2.equals("hh") || s2.equals("ii")) {
Toast.makeText(MainActivity.this, "tu appartient a la classe ZZ ", Toast.LENGTH_LONG).show();
}
}
});
}
}
我構建應用程序,然後當我用我的手機 打開它,當我打開應用程序,並把一些caractere中的EditText ,然後我把解碼應用程序關閉
這是我的代碼。 我需要幫助和謝謝
事件日誌顯示: 空PointerException: 錯誤執行task.com.android.tools.idea.uibuilder.editor.NLPreviewForm$$Lambda$221/[email protected] NullPointerException異常:空 – GHASSEN7