小编Hus*_*eem的帖子

以编程方式在android中创建pdf文件并在其中书写

我正在尝试在我的应用程序中创建一个pdf文件,将其保存在打开它的外部存储器上.保存文件对我来说不是问题,也不是打开文件,我的问题是创建文件并写入文件.所以在网上进行一些研究后,我发现了以下方法:

        File file = new File(directoryName, fileName);

        // Creating output stream to write in the newly created file
        FileOutputStream fOut = null;

        try {
            fOut = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        // Creating a new document
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);

        try {
            PdfWriter.getInstance(document, fOut);

            // Open the document for writing
            document.open();

            // Write in the document
            document.add(new Paragraph("Hello world"));
            document.close();

        } catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
Run Code Online (Sandbox Code Playgroud)

运行我的应用程序并执行上面的代码后,我收到以下错误:

java.lang.NoClassDefFoundError: Failed resolution of: …
Run Code Online (Sandbox Code Playgroud)

pdf android file itext android-pdf-api

10
推荐指数
3
解决办法
6万
查看次数

在执行 Widget 状态构建时导航

我正在构建一个简单的 Flutter 应用程序。它的启动屏幕确定用户是否登录,然后根据它重定向到登录或主/主屏幕。

我的启动屏幕是一个StatefulWidget,其状态如下所示。它使用了一个扩展的 ViewModel 类ChangeNotifier(它的代码无关紧要,所以我没有包含它)。

class _LaunchPageState extends State<LaunchPage> {
          LaunchViewModel _viewModel = LaunchViewModel();

          @override
          void initState() {
            super.initState();
            _viewModel.checkSessionStatus();
          }

          @override
          Widget build(BuildContext context) {
            return ChangeNotifierProvider<LaunchViewModel>(
              builder: (_) => _viewModel,
              child: Scaffold(
                body: Consumer<LaunchViewModel>(
                  builder: (context, viewModel, _) {
                    if (viewModel.state is LaunchInitial) {
                      return CircularProgressIndicator();
                    }
                    if (viewModel.state is LaunchLoginPage) {
                      Navigator.pushNamed(context, "login");
                    }
                    if (viewModel.state is LaunchMainPage) {
                      Navigator.pushNamed(context, "main");
                    }
                    return Container();
                  },
                ),
              ),
            );
          }
        }
Run Code Online (Sandbox Code Playgroud)

ViewModel 发出 …

flutter flutter-navigation flutter-provider

4
推荐指数
1
解决办法
1530
查看次数

使用appcompat-v7添加Android support-v4库

在我的构建gradle文件中,我有两个依赖项(appcompat-v7和设计),然后我添加到项目的任何externar jar文件

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
}
Run Code Online (Sandbox Code Playgroud)

在项目库(项目结构 - >库)中找到外部jar文件,appcompat-v7,design-22.2.1,support-v4和support-annotations-22.2.1是否正常,我不明白为什么最后两个正在添加,我认为它们是我遇到的另一个问题的原因(dexDebug).

谁会知道这是否正常?谢谢

android android-support-library android-studio

3
推荐指数
1
解决办法
878
查看次数