尝试调用虚拟方法';android.content.ContentResolverr android.id.content.Context.getContentesolver()';关于nul对象引用
我在我的应用程序中使用Telr SDK,同时使用它向我显示上下文空指针,但我使用了Volley库并在一个由“Application”类扩展的类中编写了一些方法。它一次又一次地向我显示这个错误,因为我使用了由“Application”类扩展的“APPController”类,并在“Application”标记下的清单中注册了它。如果我没有在我的项目中使用'Appcontroller'类,那么Telr网关可以完美运行,但我需要同时使用这两个类。请帮助 代码:尝试调用虚拟方法';android.content.ContentResolverr android.id.content.Context.getContentesolver()';关于nul对象引用,android,android-fragments,nullpointerexception,android-volley,android-context,Android,Android Fragments,Nullpointerexception,Android Volley,Android Context,我在我的应用程序中使用Telr SDK,同时使用它向我显示上下文空指针,但我使用了Volley库并在一个由“Application”类扩展的类中编写了一些方法。它一次又一次地向我显示这个错误,因为我使用了由“Application”类扩展的“APPController”类,并在“Application”标记下的清单中注册了它。如果我没有在我的项目中使用'Appcontroller'类,那么Telr网关可以完美运行,但我需要同时使用这两个类。请帮助 代码: public class AppCont
public class AppController extends Application {
public static final String TAG = AppController.class
.getSimpleName();
private RequestQueue mRequestQueue;
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/Rubik-Regular.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/Rubik-Regular.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "fonts/Rubik-Regular.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/Rubik-Regular.ttf");
mInstance = this;
}
public static synchronized AppController getInstance() {
return mInstance;
}
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
// set the default tag if tag is empty
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}
public void sendMessage() {
Intent intent = new Intent(Demo.this, WebviewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.putExtra(WebviewActivity.EXTRA_MESSAGE, getMobileRequest());
intent.putExtra(WebviewActivity.SUCCESS_ACTIVTY_CLASS_NAME, "com.marketplace.activity.SuccessTransationActivity");
intent.putExtra(WebviewActivity.FAILED_ACTIVTY_CLASS_NAME, "com.marketplace.activity.FailedTransationActivity");
intent.putExtra(WebviewActivity.IS_SECURITY_ENABLED, isSecurityEnabled);
startActivity(intent);
}
<application
android:name="com.marketplace.utils.AppController"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/app_icon_rect"
android:label="@string/app_name"
android:roundIcon="@mipmap/app_icon_circle"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:theme, android:name"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
AppController.java:
public class AppController extends Application {
public static final String TAG = AppController.class
.getSimpleName();
private RequestQueue mRequestQueue;
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/Rubik-Regular.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/Rubik-Regular.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "fonts/Rubik-Regular.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/Rubik-Regular.ttf");
mInstance = this;
}
public static synchronized AppController getInstance() {
return mInstance;
}
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
// set the default tag if tag is empty
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}
public void sendMessage() {
Intent intent = new Intent(Demo.this, WebviewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.putExtra(WebviewActivity.EXTRA_MESSAGE, getMobileRequest());
intent.putExtra(WebviewActivity.SUCCESS_ACTIVTY_CLASS_NAME, "com.marketplace.activity.SuccessTransationActivity");
intent.putExtra(WebviewActivity.FAILED_ACTIVTY_CLASS_NAME, "com.marketplace.activity.FailedTransationActivity");
intent.putExtra(WebviewActivity.IS_SECURITY_ENABLED, isSecurityEnabled);
startActivity(intent);
}
<application
android:name="com.marketplace.utils.AppController"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/app_icon_rect"
android:label="@string/app_name"
android:roundIcon="@mipmap/app_icon_circle"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:theme, android:name"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
我在以下方面遇到错误:Intent Intent=newintent(Demo.this,WebviewActivity.class)
Manifest.xml:
public class AppController extends Application {
public static final String TAG = AppController.class
.getSimpleName();
private RequestQueue mRequestQueue;
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/Rubik-Regular.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/Rubik-Regular.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "fonts/Rubik-Regular.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/Rubik-Regular.ttf");
mInstance = this;
}
public static synchronized AppController getInstance() {
return mInstance;
}
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
// set the default tag if tag is empty
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}
public void sendMessage() {
Intent intent = new Intent(Demo.this, WebviewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.putExtra(WebviewActivity.EXTRA_MESSAGE, getMobileRequest());
intent.putExtra(WebviewActivity.SUCCESS_ACTIVTY_CLASS_NAME, "com.marketplace.activity.SuccessTransationActivity");
intent.putExtra(WebviewActivity.FAILED_ACTIVTY_CLASS_NAME, "com.marketplace.activity.FailedTransationActivity");
intent.putExtra(WebviewActivity.IS_SECURITY_ENABLED, isSecurityEnabled);
startActivity(intent);
}
<application
android:name="com.marketplace.utils.AppController"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/app_icon_rect"
android:label="@string/app_name"
android:roundIcon="@mipmap/app_icon_circle"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:theme, android:name"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
对于仍然存在此问题的用户,如果您还没有应用程序类,可以通过创建应用程序类来解决此问题,然后使用Telr Application扩展您的应用程序类,就是这样,它将解决您的问题
public class MyApp extends TelrApplication {
public void onCreate(){
super.onCreate();
}
}
}
对于仍然存在此问题的用户,如果您还没有应用程序类,则可以通过创建应用程序类来解决此问题,然后使用Telr Application扩展应用程序类,就是这样,它将解决您的问题
public class MyApp extends TelrApplication {
public void onCreate(){
super.onCreate();
}
}
}