我试图在 webview 中使用 url 显示 pdf 文件。虽然 WebView 正在加载像 google.com 这样的网页,但当我尝试加载 pdf 的 url 时,它不会加载任何内容或引发任何异常。
该网址在谷歌浏览器桌面浏览器中加载pdf,所以我猜问题不在于网址本身。
这是我到目前为止编写的代码:
onCreateView()加载 pdf 的片段
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_brochure, container, false);
webView = view.findViewById(R.id.webView);
// webView.loadUrl("https://google.com");
webView.loadUrl("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf");
// webView.loadUrl(brochureUrl);
// Enable Javascript
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
// Force links and redirects to open in the WebView instead of in a browser
webView.setWebViewClient(new WebViewClient());
return view; …Run Code Online (Sandbox Code Playgroud) 我通过以下方式使用 room 在 SQLite 数据库中插入一些数据:
在repository类中插入数据的方法:
fun addAllConfigurableTypeToDb(
allConfigurableTypes: AllConfigurableType,
database: AppDatabase
): Boolean {
try {
val productCategoryList = arrayListOf<ConfigurableTypeEntity>()
for (configurableType in allConfigurableTypes.configurableTypeList) {
productCategoryList.add(
ConfigurableTypeEntity(
configurableType.id, configurableType.classType,
configurableType.organizationId, configurableType.name,
configurableType.code, configurableType.description,
configurableType.context, configurableType.isActive,
configurableType.isLocked, configurableType.isDeleted,
configurableType.createdBy, configurableType.createdByDate,
configurableType.lastModifiedBy, configurableType.lastModifiedByDate
)
)
}
database.configurableTypeDao.insertAll(*productCategoryList.toTypedArray())
return true
} catch (e: Exception) {
e.printStackTrace()
return false
}
}
Run Code Online (Sandbox Code Playgroud)
Dao类中的方法:
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(vararg configurableTypeEntity: ConfigurableTypeEntity)
Run Code Online (Sandbox Code Playgroud)
它一直运行良好。但是将 room 版本从 '2.5.2' 更新到 '2.6.0'、ksp 版本从 '1.8.10-1.0.9' 更新到 '1.9.20-1.0.14' 以及 kotlin 版本从 '1.8.10' …
最近我从git-hub下载了一个代码并将其同步到我的android工作室.我遇到了很多错误和问题,然后修复了它们.然而,我现在停留的最后一个问题是我的android工作室不能像你在这张图片中看到的类'FloatingActionButton'
需要注意的是,早期的许多其他类,包括'AppCompatActivity'都无法解决.将依赖项更改为以下解决了该问题
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'}
Run Code Online (Sandbox Code Playgroud)
但即使在更改依赖项后,清理构建项目,执行"使缓存无效/重新启动...","FloatingActionButton"的问题仍然存在.任何人都可以帮我解决这个问题吗?
这是存储库的链接,
这里是发生错误 的活动的java代码
我从 API 调用获取 XML 响应。
我需要此响应中的“testId”属性值。请帮我解决这个问题。
r = requests.get( myconfig.URL_webpagetest + "?url=" + testurl + "&f=xml&k=" + myconfig.apikey_webpagetest )
xmltxt = r.content
print(xmltxt)
testId = XML(xmltxt).find("testId").text
r = requests.get("http://www.webpagetest.org/testStatus.php?f=xml&test=" + testId )
Run Code Online (Sandbox Code Playgroud)
xml响应:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<statusCode>200</statusCode>
<statusText>Ok</statusText>
<data>
<testId>180523_YM_054fd7d84fd4ea7aed237f87289e0c7c</testId>
<ownerKey>dfc65d98de13c4770e528ef5b65e9629a52595e9</ownerKey>
<jsonUrl>http://www.webpagetest.org/jsonResult.php?test=180523_YM_054fd7d84fd4ea7aed237f87289e0c7c</jsonUrl>
</data>
</response>
Run Code Online (Sandbox Code Playgroud)
产生以下错误:
Traceback (most recent call last):
File "/pagePerformance.py", line 52, in <module>
testId = XML (xmltxt).find("testId").text
AttributeError: 'NoneType' object has no attribute 'text'
Run Code Online (Sandbox Code Playgroud) 我想打印字符数组(作为字符串),但它在运行时显示一个空字符串
初始化:
char str1[6]= "Black";
char str2[7]= "Yellow";
Run Code Online (Sandbox Code Playgroud)
printf 语句:
printf ("%s = %d Bath\n",str1,a);
printf ("%s = %d Bath\n",str2,a);
Run Code Online (Sandbox Code Playgroud)
预期的:
Black = 150 Bath
Yellow = 150 Bath
Run Code Online (Sandbox Code Playgroud)
输出
Black = 150 Bath
= 150 Bath
Run Code Online (Sandbox Code Playgroud)
我尝试在没有大小数字的情况下进行初始化,例如char str2[]= "Yellow";
或使用 C++ cout 来显示
原始代码:
char str1[6]= "Black";
char str2[7]= "Yellow";
Run Code Online (Sandbox Code Playgroud)