我想知道这个错误发生的原因是什么......
我正在开发一个CRUD,并且由于某种原因破坏了它。许多代码并带你去分析,我有什么办法可以知道这个错误被触发的地方
MainActivity.java
package br.com.crud.Activitys;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import br.com.crud.R;
public class MainActivity extends Activity
{
Button btnView;
Button btnCadastro;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnCadastro = (Button) findViewById(R.id.btnCadastro);
btnView = (Button) findViewById(R.id.btnView);
btnView.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
}
});
btnCadastro.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), NovoProdutoActivity.class);
startActivityForResult(i, 1);
}
});
}
}
NovoProdutoActivity.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.crud.Activitys;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import br.com.crud.R;
/**
*
* @author muky
*/
public class NovoProdutoActivity extends Activity{
Button btnSalvar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.novo_produto);
btnSalvar = (Button) findViewById(R.id.btnSalvar);
btnSalvar.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Produto Salvo com Sucesso", 6).show();
}
});
}
}
logcat的
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.crud"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" >
<activity android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- View Cadastro de Produto -->
<activity
android:name="NovoProdutoActivity"
android:label="NovoProduto"/>
<!-- View Listar Produtos -->
<activity
android:name="ListaProdutoActivity"
android:label="ListarProdutos"/>
</application>
</manifest>
答案 0 :(得分:0)
代码中的主要活动为br.com.crud.Activitys.MainActivity
,而清单显示为br.com.crud.MainActivity
。确保完整的类名在清单和代码中一致。