[英]android application crash when i try to open activity
every time i try to open a business my apa crashes I want the app to send the data present in the input text via url to be able to take them via a php script do you have any solution?每次我尝试开展业务时,我的 apa 崩溃我希望应用程序通过 url 发送输入文本中存在的数据,以便能够通过 php 脚本获取它们你有什么解决方案吗? I have tried several changes but nothing works for now I don't understand where the mistake can be, any help?我已经尝试了几次更改,但现在没有任何效果我不明白错误可能出在哪里,有什么帮助吗?
it's probably a simple stupid mistake, but one I can't find.这可能是一个简单的愚蠢错误,但我找不到。 I've attached java, xml file, and logcat.我附上了 java、xml 文件和 logcat。
java code: java 代码:
String nomep;
int prezzop, tempop;
Button btnInserisci;
RadioButton aggiorna;
RadioButton servizio;
RadioButton ricambio;
RadioButton accessori;
EditText nome;
EditText prezzo;
EditText tempo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inserisci);
aggiorna = findViewById(R.id.aggiorna);
servizio = findViewById(R.id.servizio);
ricambio = findViewById(R.id.ricambio);
accessori = findViewById(R.id.acessori);
nome = findViewById(R.id.nomeProdotto);
prezzo = findViewById(R.id.prezzo);
tempo = findViewById(R.id.tempo);
//pulsante in ascolto del "click"
btnInserisci = findViewById(R.id.scanInserisci);
btnInserisci.setOnClickListener(this);
scan();
}
//se il pulsante viene cliccato apre la funzione "scan"
@Override
public void onClick(View v) {
scan();
}
private void scan(){
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setCaptureActivity(CaptureAct.class);
integrator.setOrientationLocked(false);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setPrompt("Scannerizzando il codice..");
integrator.initiateScan();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null){
if(result.getContents() != null){
if(aggiorna.isChecked()) {
if(accessori.isChecked()){
//stringa sito da cambiare con quella del server funzionante
String sito = "https://www.gorinsights.it/scuola/server.php?nuovo=no&aggiungi=si&tabella=accessori&id=" + result.getContents();
gotoUrl(sito);
}else if (ricambio.isChecked()){
//stringa sito da cambiare con quella del server funzionante
String sito = "https://www.gorinsights.it/scuola/server.php?nuovo=no&aggiungi=si&tabella=ricambio&id=" + result.getContents();
gotoUrl(sito);
}else if (servizio.isChecked()){
Toast.makeText(this,"non puoi aggiungere quantità ad un servizio", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(this,"scegli dove aggiornare il prodotto", Toast.LENGTH_LONG).show();
}
}else{
if(accessori.isChecked()){
nomep = nome.getText().toString();
prezzop = Integer.valueOf(prezzo.getText().toString());
//stringa da aggiustare
String sito = "https://www.gorinsights.it/scuola/server.php?nuovo=si&tabella=accessori&id=" + result.getContents()+"&nome="+nomep+"&prezzo="+prezzop;
gotoUrl(sito);
}else if (ricambio.isChecked()){
nomep = nome.getText().toString();
prezzop = Integer.valueOf(prezzo.getText().toString());
//stringa da aggiustare
String sito = "https://www.gorinsights.it/scuola/server.php?nuovo=si&tabella=ricambio&id=" + result.getContents()+"&nome="+nomep+"&prezzo="+prezzop;
gotoUrl(sito);
}else if (servizio.isChecked()){
nomep = nome.getText().toString();
prezzop = Integer.valueOf(prezzo.getText().toString());
tempop=Integer.valueOf(tempo.getText().toString());
//stringa da aggiustare
String sito = "https://www.gorinsights.it/scuola/server.php?nuovo=si&tabella=servizio&id=" + result.getContents()+"&nome="+nomep+"&prezzo="+prezzop+"&tempo="+tempop;
gotoUrl(sito);
}else{
Toast.makeText(this,"scegli dove inserire il prodotto", Toast.LENGTH_LONG).show();
}
}
}
else
{
Toast.makeText(this,"nessun risultato", Toast.LENGTH_LONG).show();
}
}else {
super.onActivityResult(requestCode, resultCode, data);
}
}
private void gotoUrl(String sito) {
Uri uri = Uri.parse(sito);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// Verify that the intent will resolve to an activity
if (intent.resolveActivity(getPackageManager()) != null) {
// Here we use an intent without a Chooser unlike the next example
startActivity(intent);
}
}
xml file: xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
tools:context=".inserisci">
<Button
android:id="@+id/scanInserisci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="scan"
android:translationX="400px"
android:translationY="1500px" />
<RadioButton
android:id="@+id/aggiungi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aggiungi nuovo"
android:translationX="100px"
android:translationY="200px" />
<RadioButton
android:id="@+id/servizio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="servizio"
android:translationX="750px"
android:translationY="350px" />
<RadioButton
android:id="@+id/ricambio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ricambio"
android:translationX="400px"
android:translationY="350px" />
<RadioButton
android:id="@+id/acessori"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="acessori"
android:translationX="80px"
android:translationY="350px" />
<RadioButton
android:id="@+id/aggiorna"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aggiorna quantià"
android:translationX="600px"
android:translationY="200px" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationY="500px"
android:id="@+id/nomeProdotto">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="nome prodotto" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationY="700px"
android:id="@+id/prezzo"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="prezzo" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationY="1000px"
android:id="@+id/tempo"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="tempo necessario (obbligatorio solo per i servizi)" />
</com.google.android.material.textfield.TextInputLayout>
crash log:崩溃日志:
2021-01-26 13:46:47.709 8672-8672/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.scanner, PID: 8672
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.scanner/com.example.scanner.inserisci}: android.view.InflateException: Binary XML file line #64: com.google.android.material.textfield.TextInputEditText cannot be cast to android.view.ViewGroup
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: android.view.InflateException: Binary XML file line #64: com.google.android.material.textfield.TextInputEditText cannot be cast to android.view.ViewGroup
Caused by: java.lang.ClassCastException: com.google.android.material.textfield.TextInputEditText cannot be cast to android.view.ViewGroup
at android.view.LayoutInflater.rInflate(LayoutInflater.java:868)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.scanner.inserisci.onCreate(inserisci.java:36)
at android.app.Activity.performCreate(Activity.java:7224)
at android.app.Activity.performCreate(Activity.java:7213)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Your error message says it all:您的错误消息说明了一切:
Caused by: android.view.InflateException: Binary XML file line #64: com.google.android.material.textfield.引起:android.view.InflateException:二进制 XML 文件第 64 行:com.google.ZC31B323644CECA19B323644ECCE19 TextInputEditText cannot be cast to android.view.ViewGroup TextInputEditText 无法转换为 android.view.ViewGroup
You are trying to cast a <com.google.android.material.textfield.TextInputLayout
to an EditText, they're not the same thing:您正在尝试将<com.google.android.material.textfield.TextInputLayout
转换为 EditText,它们不是一回事:
inside onCreate you have:在 onCreate 你有:
nome = findViewById(R.id.nomeProdotto);
you have defined this as您已将其定义为
EditText nome; <-- this is defined in your activity
but in your xml you have但在你的 xml 你有
<com.google.android.material.textfield.TextInputLayout <-- this is defined in your xml
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationY="500px"
android:id="@+id/nomeProdotto">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="nome prodotto" />
</com.google.android.material.textfield.TextInputLayout>
what you probably wanted to do was something like this:你可能想做的是这样的:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationY="500px">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nomeProdotto"
android:hint="nome prodotto" />
</com.google.android.material.textfield.TextInputLayout>
Updated your xml code.更新了您的 xml 代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
tools:context=".inserisci">
<Button
android:id="@+id/scanInserisci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="scan"
android:translationX="400px"
android:translationY="1500px" />
<RadioButton
android:id="@+id/aggiungi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aggiungi nuovo"
android:translationX="100px"
android:translationY="200px" />
<RadioButton
android:id="@+id/servizio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="servizio"
android:translationX="750px"
android:translationY="350px" />
<RadioButton
android:id="@+id/ricambio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ricambio"
android:translationX="400px"
android:translationY="350px" />
<RadioButton
android:id="@+id/acessori"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="acessori"
android:translationX="80px"
android:translationY="350px" />
<RadioButton
android:id="@+id/aggiorna"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aggiorna quantià"
android:translationX="600px"
android:translationY="200px" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationY="500px">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/nomeProdotto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="nome prodotto" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationY="700px">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/prezzo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="prezzo" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationY="1000px">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tempo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="tempo necessario (obbligatorio solo per i servizi)" />
</com.google.android.material.textfield.TextInputLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.