Tag: java的

意图开始时的RuntimeException

无论高度如何,我都会在每个屏幕的开头都收到此exception。 java.lang.RuntimeException:二进制XML文件行#25:您必须提供layout_height属性。

片段在尝试从活动接收对象时崩溃

美好的一天, 我有一个问题,我的活动正在进行网络调用,当网络调用完成时,它使用从调用接收到的JSON对象中的数据对活动进行一些更改,然后将对象传递给同样的活动。 这些片段位于TabLayout中。 我遇到的问题是,如果我放入System.out.println(),它会打印出正确的数据。 我想要设置的那一刻说一个TextView与我在Fragment中收到的数据应用程序崩溃与Nullpointer。 当我使用Android工作室中的Debug调试它时,由于某种原因,TextView I设置始终为null。 执行初始网络呼叫的活动代码: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_listings); ButterKnife.bind(this); setSupportActionBar(toolbar); handleIntent(getIntent()); } private void handleIntent(Intent aIntent) { if (aIntent != null) { String tradeType = aIntent.getStringExtra(“itemType”); String tradeId = aIntent.getStringExtra(“itemId”); presenter = new ItemPresenterImpl(this, ItemBuyNowActivity.this); presenter.doListingServiceCall(tradeId); // <——- This is the where I send the Trade Id […]

在一个请求中上传JSON和二进制文件

我希望创建一个RESTful API,用于Android和iOS应用程序。 到目前为止,我一直在尝试在服务器上使用Jersey,然后在客户端使用相应的http库。 目前我一直使用multipart/related作为请求的mimetype,JSON构成了身体的第一部分,然后是jpeg图像作为第二部分。 到目前为止,我遇到了向服务器发出请求的问题,从Jersey获得了406 Not Acceptable 。 我注意到multipart/related主要用于发送电子邮件。 实际上是否有一种方法可以支持混合类型内容作为上传,或者我在这种情况下完全误解了multipart/related的用法?

Android动态微调器更新

我正在使用Android和Spinners,我需要一些帮助。 我有一个创建两个微调器和一个按钮的类。 第一个微调器是我的类别,第二个是我的子类别。 我想要做的是动态更新第二个微调器(spinner2)。 我一直在尝试使用adapter2.clear(),但崩溃了android,错误“无法启动活动componentinfo不支持的操作” 这是我的代码: public class MyClass extends MyBaseClass { int category; int sub_category; ArrayAdapter adapter2; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.quizes); //CATEGORY INFO final String[] items1 = new String[] {“One”, “Two”, “Three”}; final Spinner spinner1 = (Spinner) findViewById(R.id.spinner1); ArrayAdapter adapter1 = […]

在同一方法上动态传递不同类型的对象

我想编写一个动态接收不同类型对象的方法。 一旦我收到动态对象,我就有了逻辑内部方法,可以根据与该对象关联的属性执行某些操作。 它将如下所示: MainClass{ class1 obj1;//all these are pojo class2 obj2; class3 obj3; method1() } method1(){ if(dynamic_object.property 1 == true){ callmethod2(dynamic_object.property 1) } else{ callmethod3(dynamic_object.property 1) } } 这里dynamic_objects是不同类型的。 我怎样才能在Java中实现这一目标? 我不想在这里使用reflection 。

在java android中点击按钮语言改变

我正在寻找一种方法来实现按钮onclick触发的语言更改。 我在适当的文件夹中创建了正确的strings.xml(例如res / values-en /)这是我的按钮代码: Button setEN_bt = (Button) findViewById(R.id.setEN); setEN_bt.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Locale locale_en = new Locale(“en”); Locale.setDefault(locale_en); Configuration config_en = new Configuration(); config_en.locale = locale_en; getBaseContext().getResources().updateConfiguration(config_en, getBaseContext().getResources().getDisplayMetrics()); } }); 所以基本上我用onclick更改了语言环境,但之后页面没有刷新(为什么要… :))。 有人可以告诉我如何刷新/重新加载活动吗? Thanx提前帮助。

使用getExternalFilesDir保存Android不一致的图片

在我的应用程序中,我正在尝试拍照,保存它,然后使用Android开发人员教程中提供的代码将其添加到ImageView private static final int REQUEST_IMAGE_CAPTURE = 1; private String lastImagePath; //Create temporary image file using getExternalFilesDir() private File createImageFile() throws IOException{ String timestamp = new SimpleDateFormat(“yyyyMMdd_HHmmss”).format(new Date()); String imageFileName = “JPEG_” + timestamp + “_”; File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, “.jpg”, storageDir); lastImagePath = image.getAbsolutePath(); return image; } //Start picture intent […]

如何在JAVA中读取.txt文件的特定部分

我一直试图弄清楚如何从.txt文件中读取。 我知道如何阅读整个文件,但我在阅读文件中两个特定点之间遇到困难。 我也试图使用扫描仪类,这是我到目前为止: public void readFiles(String fileString)throws FileNotFoundException{ file = new File(fileString); Scanner scanner = null; line=””; //access file try { scanner = new Scanner(file); } catch (FileNotFoundException e) { System.out.println(“File not found.”); } // if more lines in file, go to next line while (scanner.hasNext()) { line = scanner.next(); if (scanner.equals(“BGSTART”)) //tag in the […]

声明后,Java中的数组大小是固定的吗?

我想知道声明后Java数组是否已修复。 当我们这样做时: int a[10]; 然后我们可以这样做: a = new int [100]; 我不确定第一个语句是否已经分配了一些内存,第二个语句是否分配了一大块内存并重新分配并覆盖了以前的引用。

Android Notification在应用程序启动时触发

我正在尝试让我的每日通知服务正常工作,但我遇到了问题。 我应该只在将来的某个特定时间收到通知,但我注意到了 if (time_that_i_set_for_notification < current_time_of_the_day) notification triggers at the boot of my app 这是错误的,因为在这种情况下,通知应该仅在第二天触发,而不是在我启动应用程序的瞬间。 这是我试图让事情奏效的尝试: 我在我的MainActivity,onCreate()方法中调用它 : private void scheduleNotification(int hour, int minute){ Intent notificationIntent = new Intent(this, NotificationReceiver.class); notificationIntent.putExtra(“notifId”, notifId); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, notifId, notificationIntent, 0); // Set the alarm to start at approximately at a time DatePicker datePicker = new DatePicker(this); […]