I see an image with Intent.ACTION_VIEW and when closing the following error occurs, I am thinking it is in MainActivity.class:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.emerson.barcellos.mgordenservicopremium, PID: 9168
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emerson.barcellos.mgordenservicopremium/com.emerson.barcellos.mgordenservicopremium.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.emerson.barcellos.mgordenservicopremium.Fragments.AlterarOsFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.emerson.barcellos.mgordenservicopremium.Fragments.AlterarOsFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.support.v4.app.Fragment.instantiate(Fragment.java:446)
at android.support.v4.app.FragmentState.instantiate(Fragment.java:108)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:2058)
at android.support.v4.app.FragmentController.restoreAllState(FragmentController.java:158)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:328)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:88)
at com.emerson.barcellos.mgordenservicopremium.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:6374)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.InstantiationException: class com.emerson.barcellos.mgordenservicopremium.Fragments.AlterarOsFragment has no zero argument constructor
at java.lang.Class.newInstance(Class.java:1641)
at android.support.v4.app.Fragment.instantiate(Fragment.java:435)
at android.support.v4.app.FragmentState.instantiate(Fragment.java:108)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:2058)
at android.support.v4.app.FragmentController.restoreAllState(FragmentController.java:158)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:328)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:88)
at com.emerson.barcellos.mgordenservicopremium.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:6374)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NoSuchMethodException: <init> []
at java.lang.Class.getConstructor(Class.java:531)
at java.lang.Class.getDeclaredConstructor(Class.java:510)
at java.lang.Class.newInstance(Class.java:1639)
at android.support.v4.app.Fragment.instantiate(Fragment.java:435)
at android.support.v4.app.FragmentState.instantiate(Fragment.java:108)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:2058)
at android.support.v4.app.FragmentController.restoreAllState(FragmentController.java:158)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:328)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:88)
at com.emerson.barcellos.mgordenservicopremium.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:6374)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
My Fragment.class
...
Intent inte = new Intent(Intent.ACTION_VIEW);
inte.setDataAndType(Uri.parse(uri.toString()), "*/*");
startActivity(inte);
...
MainActivity.class
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
View headerView;
DrawerLayout drawer;
FragmentTransaction ft;
private int id;
private int RESULT_BARCODE = 3;
public static DataBaseHandler db;
final ContentValues values = new ContentValues();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
db = DataBaseHandler.getInstance(this);
/**
Cursor cursor = db.Select(DataBaseHandler.TABLE_OS, null, null, null, null, null, null, null);
int index0 = cursor.getColumnIndex(DataBaseHandler.KEY_OS_ID);
if (cursor.moveToFirst()) {
do {
values.clear();
values.put(DataBaseHandler.KEY_OS_ID_SEQUENCIA, cursor.getString(index0));
db.Update(DataBaseHandler.TABLE_OS, values, DataBaseHandler.KEY_OS_ID + "=?", new String[]{cursor.getString(index0)});
Log.v("aviso", cursor.getString(index0));
}
while (cursor.moveToNext());
}**/
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
selectedMenu();
}
};
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
headerView = navigationView.getHeaderView(0);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (bundle != null) {
int numero = bundle.getInt("numero");
if (numero != 0) {
ft.replace(R.id.container, new HomeFragment(), "home").addToBackStack("tag_back").commit();
ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.container, new AlterarOsFragment(bundle.getInt("numero")), "os").addToBackStack("tag_back").commit();
} else {
ft.replace(R.id.container, new HomeFragment(), "home").commit();
}
} else {
ft.replace(R.id.container, new HomeFragment(), "home").commit();
}
perfil();
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
id = item.getItemId();
drawer.closeDrawer(GravityCompat.START);
return true;
}
void selectedMenu() {
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.container);
ft = getSupportFragmentManager().beginTransaction();
if (id == R.id.nav_home) {
if (!currentFragment.getTag().equals("home")) {
ft.replace(R.id.container, new HomeFragment(), "home");
ft.addToBackStack("tag_back");
ft.commit();
}
} else if (id == R.id.nav_abrir) {
// if (Funcoes.idUltimOs()) {
// Funcoes.popUpPremium();
// } else {
Intent intentA = new Intent(MainActivity.this, AbrirOsActivity.class);
intentA.putExtra("edit", false);
intentA.putExtra("numero", 1);
startActivity(intentA);
finish();
// }
} else if (id == R.id.nav_alterar) {
new Os(MainActivity.this, 0).popUpIdOs(getSupportFragmentManager());
} else if (id == R.id.nav_pesuisar) {
if (!currentFragment.getTag().equals("pesquisar")) {
ft.replace(R.id.container, new OsListFragment(null, null, false), "pesquisar");
ft.addToBackStack("tag_back");
ft.commit();
}
} else if (id == R.id.nav_scanner) {
Intent intent = new Intent(MainActivity.this, BarcodeScanner.class);
intent.putExtra("tipo", true);
intent.putExtra("edit", false);
startActivityForResult(intent, RESULT_BARCODE);
// ContentValues values = new ContentValues();
// values.put(DataBaseHandler.KEY_OS_GRUPO, "9y8FwQTy");
// db.Update(DataBaseHandler.TABLE_OS, values, null, null);
//new AtualizaServerToLocal(getBaseContext(), 1, 2).execute();
} else if (id == R.id.nav_clientes) {
if (!currentFragment.getTag().equals("clientes")) {
ft.replace(R.id.container, new ClientesFragment(), "clientes");
ft.addToBackStack("tag_back");
ft.commit();
}
}
/**else if (id == R.id.nav_grupos) {
if (!currentFragment.getTag().equals("grupos")) {
ft.replace(R.id.container, new ChartFragment(), "grupos");
ft.addToBackStack("tag_back");
ft.commit();
}
} **/
else if (id == R.id.nav_cadastro) {
if (!currentFragment.getTag().equals("cadastro")) {
ft.replace(R.id.container, new CadastrosFragment(1), "cadastro");
ft.addToBackStack("tag_back");
ft.commit();
}
} else if (id == R.id.nav_financeiro) {
if (!currentFragment.getTag().equals("financeiro")) {
ft.replace(R.id.container, new FinanceiroFragment(), "financeiro");
ft.addToBackStack("tag_back");
ft.commit();
}
} else if (id == R.id.nav_configuracao) {
Intent intent = new Intent(MainActivity.this, ConfiguracaoActivity.class);
startActivity(intent);
// this.finish();
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == RESULT_BARCODE) {
String contents = data.getStringExtra("SCAN_RESULT");
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.container, new OsListFragment(DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_BARCODE, contents, false), "pesquisa").addToBackStack("tag_back").commit();
}
}
}
public void perfil() {
Cursor c = db.Select(DataBaseHandler.TABLE_USER, null, null, null, null, null, null, null);
if (c.moveToNext()) {
int iNome = c.getColumnIndex(DataBaseHandler.KEY_USER_NAME);
int iEmpresa = c.getColumnIndex(DataBaseHandler.KEY_USER_EMPRESA);
int iFoto = c.getColumnIndex(DataBaseHandler.KEY_USER_FOTO);
byte[] ft = c.getBlob(iFoto);
Bitmap bitmap = null;
if (ft != null) {
bitmap = BitmapFactory.decodeByteArray(ft, 0, ft.length);
} else {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_emotion_24dp);
}
setUserData(c.getString(iNome), c.getString(iEmpresa), bitmap);
}
}
public void setUserData(String user, String email, Bitmap avatar) {
((TextView) headerView.findViewById(R.id.txtUserEmail)).setText(email);
((TextView) headerView.findViewById(R.id.txtUsername)).setText(user);
if (avatar != null)
((ImageView) headerView.findViewById(R.id.imgAvatar)).setImageDrawable(new RoundImage(avatar));
}
}