2017-08-16 32 views
-3

我在Android studio 2.3.3中创建了一个新项目。 XML中只添加了一个TextView。当我试图调试代码时,它会引发异常。以下是事件日志。错误“根元素类型”html“的文档类型声明必须以'>'结尾”

你能告诉我如何解决这个问题吗?

错误日志

8/16/2017 
9:26 AM `Gradle` sync started 

9:27 AM `Gradle` sync completed 

9:27 AM Executing tasks: 

    [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies] 

9:27 AM `Gradle` build finished in 35s 276ms 

9:30 AM Executing tasks: `[:app:assembleDebug]` 

9:31 AM `Gradle` build finished in 41s 685ms 

9:35 AM `JDOMParseException`: Error on line 1: The document type declaration for root element type "html" must end with '>'. 

Java代码

import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v4.widget.TextViewCompat; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.View; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.widget.TextView; 

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     TextView tv=new TextView(this); 
     tv.setText("Hello"); 
     setContentView(tv); 
     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 
} 

活动主要XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.zfu.app2.MainActivity"> 
<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 
</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_main" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    app:srcCompat="@android:drawable/ic_dialog_email" /> 

</android.support.design.widget.CoordinatorLayout> 

内容主要XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.example.zfu.app2.MainActivity" 
tools:showIn="@layout/activity_main"> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" /> 

</android.support.constraint.ConstraintLayout> 
+0

通过日志,构建成功。错误消息似乎与调试无关。您可以尝试安装apk(通过命令行或android studio),然后单击**将调试器附加到Android Studio中的Android进程**按钮以调试您的应用程序。 – cmoaciopm

+0

请勿在评论中张贴代码;张贴在你的问题。 –

回答

0

没有什么问题的代码和XML文件。有一些场景你可以尝试:

1)只需运行应用程序,然后附加调试程序处理选项。

2),用于调试不同设备上尝试。有时候还有设备问题。

3)无效缓存/重新启动机器人工作室。

4)删除您已经应用了所有调试点。当您将调试点附加到错误的位置时,它会崩溃android应用程序运行。

尝试这一切。如果没有任何工作,然后让我知道会尝试进一步。由于

+0

1>我运行应用程序,然后附加调试程序来处理选项,但状态是'安装APK' – Alex

+0

它现在工作吗? –

+0

1>我运行应用程序,然后附加调试器来处理选项,但状态是'安装APK',然后显示一个对话框'警告:调试信息可能不可用。请关闭使用ADB的其他应用程序:Monitor,DDMS,Eclipse'2>我在Studio的Emulator上试用它,我需要其他模拟器吗? 3>我重新启动PC和android studio很多,但它仍然无法工作。 4>所有的代码都来自android studio,我没有添加任何代码,除了文本视图 – Alex

0

为您查询“警告:调试信息不​​可用”

请试试这个:

如果你看看[文件菜单 - >]设置 - >调试 - >步进,你会看到一个列表“不要进入这些类“,可能在那里列出”java。*“。是这样吗?你可以把它关掉。

显然调试信息不​​可用。根据此线程:

不幸的是,JDK类具有调试信息的参数和局部变量剥离。

几年前,我提出了要求,即Idea应该推断从源代码中的必要信息(基本转换变量名索引到方法的局部变量): 调试器:显示变量信息时没有调试信息

请表决/发表评论。

作为一种解决方法,您可以从源代码重新编译JDK,但是您需要排除一些没有附加所有必需源代码的类。有趣的是,你可以下载测试版的Java 6u18,其中包含调试信息(在DEBUG软件包中)。

相关问题