English 中文(简体)
固定的电文如果原材料夹不空,则无效。
原标题:setContentView() returns null if raw resource folder is not empty

我的主要活动始于儿童活动。 在儿童中onCreate() 我呼吁:

setContentView(R.layout.console);
TextView tv = (TextView)findViewById(R.id.console);

只要我的原始资源是空的,这项工作就能够找到。 当我把任何档案输入时,findViewById() Returncode>null。 我无法发现,为什么原始文件与缺乏寻找非物资源之间存在干扰。

问题回答

我试图利用NetBeans和Eclipse,R.java载有所有必要的条目,没有身份证冲突。 如果在原始文件夹中添加一个档案,则在R.java中正确地添加了该档案,而没有任何其他变化。

InlogCat 在我尝试使用第tv号案文之后,我就立即获得一个无效的例外。 当我在其申报/首次登记之后立即将这一数值写到该记录上时,该数值即为无效。

@Override
protected void onCreate(Bundle savedInstanceState)
{
  Log.i("Calling onCreate()");
  super.onCreate(savedInstanceState);
  setContentView(R.layout.console);
  TextView tv = (TextView)findViewById(R.id.console);
  Log.i("tv = " + tv);
}

这似乎是一个问题,因为这项活动受到MAIN活动的影响。

Intent intent = new Intent(getContext(), ConsoleActivity.class);
int requestCode = Activity.RESULT_OK;
startActivityForResult(intent, requestCode);

青少年活动的排外文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

   <ScrollView
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <TextView
         android:id="@+id/console"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"/>
    </ScrollView>

   </LinearLayout>

</LinearLayout>

I found a workaround. The code was part of a library. In the library project, I did not include the raw resource directory, because I do not use raw resources in the library. Now I created a raw directory with some (dummy) files in the library project, and... the null pointer error when adding a raw directory with files in the apps project disappeared miraculousely.

感谢你们的帮助,激励我。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签