我的问题是我想创建xml树并获得一个简单的字符串对象(甚至是char*).我无法将xml保存到文件中.
所以在输入中我有xmlDocPtr和完整的xml树,并希望得到包含xml但不使用文件的字符串.
请注意.
在我上次的采访中,我被问到一个关于java中所有Singleton实现的标准问题.他们都有多糟糕.
我被告知,即使静态初始化也很糟糕,因为构造函数中出现未经检查的异常的可能性:
public class Singleton {
private static Singleton instance = new Singleton();
public static Singleton getInstance() {
return instance;
}
private Singleton() {
throw new RuntimeException("Wow... Exception in Singleton constructor...");
}
}
Run Code Online (Sandbox Code Playgroud)
他们还告诉我,Exception将是"ClassNotFoundException",因此在真正的应用程序中找到问题非常困难.
我试图得到那个例外:
public static void main(String[] args) {
new Thread(new Runnable(){
public void run() {
Singleton.getInstance();
}
}).start();
}
Run Code Online (Sandbox Code Playgroud)
但我唯一得到的是ExceptionInInitializerError ......
我搜索了这个例外以及我发现的所有地方 - 他们都谈到了我在采访中被告知的同样问题.没有关于"实施"=)
感谢您的关注.
我有一个小部件和4个按钮.这些按钮实际上是其他应用程序的快捷方式.我使用以下代码为每个按钮设置了onClick待定意图:
Intent i = context.getPackageManager().getLaunchIntentForPackage(s);
PendingIntent pi = PendingIntent.getActivity(context, 0, i, Intent.FLAG_ACTIVITY_NEW_TASK);
remoteViews.setOnClickPendingIntent(curIconId, pi);
Run Code Online (Sandbox Code Playgroud)
通常它工作正常,但有时它不会做任何事情,在logcat中我看到一个SendIntentException,消息"无法发送待定意图".
如果我更新小部件(即再次设置挂起的意图),它再次正常工作.
关于它为什么有时会崩溃的任何想法?
谢谢
我想制作一个非常简单的小部件:
它必须只包含一个图像视图
1)对于传入的短信,它应该改变图像
2)点击它也应该改变图像
我尝试使用ImageButton但是失败了:在sms接收事件上更改图像时出现问题:新图像的比例错误.
无论如何,现在我想制作一个没有任何其他东西的ImageView.
问题是我无法处理onClick事件:
我有一个正在运行的服务,应该处理所有事件:收到短信并点击:
widget提供者:
public class MyWidgetProvider extends AppWidgetProvider {
@Override
public void onDisabled(Context context) {
context.stopService(new Intent(context, UpdateService.class));
super.onDisabled(context);
}
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
Intent intent = new Intent(context, UpdateService.class);
context.startService(intent);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
for (int i = 0; i < appWidgetIds.length; i++) {
int appWidgetId = appWidgetIds[i];
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
Intent widgetClickIntent = new Intent(context, UpdateService.class); …Run Code Online (Sandbox Code Playgroud) 我正在开发一个只支持两个方向的应用程序,纵向和反向肖像,所以我sensorPortrait在我的清单中写了" ",它运行良好.
问题是,我想为这两个方向使用不同的布局.
启用sensorPortrait禁用" onConfigurationChange"呼叫.
我用:
orientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int i) {
int newOrientation = getScreenOrientation();
if (newOrientation != orientation) {
orientation = newOrientation;
if (newOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
...
setContentView(R.layout.main);
} else if (newOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
...
setContentView(R.layout.main_reverse_portrait);
}
}
}
};
orientationEventListener.enable();
Run Code Online (Sandbox Code Playgroud)
问题是这个代码在更改方向后被调用,因此当用户首先旋转手机时,他们会看到之前的布局,由Android自动旋转,然后是正确的布局.看起来不可接受,你知道怎么解决吗?
我只知道通过id获取视图的一种方法:
getViewById(R.drawable.imageButton)
Run Code Online (Sandbox Code Playgroud)
但是,如果我没有活动(开发一个小部件应用程序),我该如何获得这个imageButton?
我能够得到一个背景.我想这足以获得视图 - 上下文只包含一个小部件不是吗?如果没有 - 那么如何获取每个小部件视图?
我现在正试图复活一个项目.getMainLooper()上有一个例外...
我认为MainLooper初始化可能存在问题,并在此之前添加了Looper.prepareMainLoop().
异常告诉我,已经有一个针对该对象的looper被抛出......
然后我尝试用Looper.myLooper()替换getMainLooper()并且它有效...
但我不明白为什么=)
事实上,我没有区分这两件事.我认为在我的项目中使用getMainLooper()的地方,它是应用程序的真正主要循环器的最佳位置,但我得到了我得到的...
请解释.
感谢您的关注