A) Why when i try to run the app i get this error?
My Crash Log Error
java.lang.RuntimeException: Unable to start activity java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6688) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) Caused by: java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation. at android.support.test.InstrumentationRegistry.getInstrumentation(InstrumentationRegistry.java:45) at android.support.test.InstrumentationRegistry.getContext(InstrumentationRegistry.java:75) at com.wachipi.challengetv.GuidaTvActivity$GetData.onPreExecute(main.java:76) at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:613) at android.os.AsyncTask.execute(AsyncTask.java:560) at com.wachipi.challengetv.GuidaTvActivity.onCreate(main.java:68) at android.app.Activity.performCreate(Activity.java:6912) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6688) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Unable to start activity ComponentInfojava.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.
What caused that? I'm yet learning and i'll appreciate if you can explain more.
This is my code
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.support.design.widget.TabLayout;
import android.widget.ListView;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static android.support.test.InstrumentationRegistry.getContext;
import static com.google.android.gms.internal.zzahn.runOnUiThread;
/**
* Created by GB on 28/03/18.
*/
public class Main extends AppCompatActivity {
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
private ProgressDialog pDialog;
//url per il recupero del JSON
private static String url = "there is an url trust me. But i need to hide";
private ListView TodayMenu;
ArrayList<HashMap<String, String>> DATA;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toolbar toolbargtv = (Toolbar) findViewById(R.id.toolbargtv);
setSupportActionBar(toolbargtv);
//getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ViewPager viewer = (ViewPager) findViewById(R.id.viewer);
setupViewPager(viewer);
TabLayout tabsgtv = (TabLayout) findViewById(R.id.tabsgtv);
tabsgtv.setupWithViewPager(viewer);
DATA = new ArrayList<>();
TodayMenu = (ListView) findViewById(R.id.todayMenu);
new GetData().execute();
}
private class GetData extends AsyncTask<Void,Void,Void>{
@Override
protected void onPreExecute(){
super.onPreExecute();
//Mostro avviso
pDialog = new ProgressDialog(getContext());
pDialog.setMessage("Attendi..");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0){
HttpHandler sh = new HttpHandler();
//faccio una richiesta al server e attendo risposta
String jsonStr = sh.makeServiceCall(url);
Log.e("RAW-JSON: ","Retrieve RAW-Json is "+jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
String DATESTRING = jsonObj.getString("date");
JSONObject DATE = new JSONObject(DATESTRING); //Log.d("STAMPA","DATESTRING"+DATESTRING);
//Log.d("PER FAVORE","IERI ERA "+Ieri);
//ESTRAGGO E INSERISCO DOVE MI SERVE
String Yesterday = DATE.getString("ieri");
String Today = DATE.getString("oggi");
String Tomorrow = DATE.getString("domani");
} catch (JSONException e) {
runOnUiThread(new Runnable(){
@Override
public void run(){
Toast.makeText(getContext(),"Errore nel recupero dati",Toast.LENGTH_LONG).show();
}
});
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(Void result){
super.onPostExecute(result);
//tolgo il caricamento di pDialog
if (pDialog.isShowing())
pDialog.dismiss();
}
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new YesterdayFragment(),"" ); //i can set from here the name of tabs but how is the name from by Json?
adapter.addFragment(new TodayFragment(), "");
adapter.addFragment(new TomorrowFragment(), "");
viewPager.setAdapter(adapter);
}
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
}
You are trying to use a context in pDialog = new ProgressDialog(getContext());
but instead of using the context like this
(activity context) or getApplicationContext()
you are using an InstrumentationRegistry context, which in your case is not useful because that's not a test, see your import import static android.support.test.InstrumentationRegistry.getContext;
Just fix the context to use the right one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With