我是Android新手,我正在尝试运行我的第一个程序.但是,基于我在互联网上的搜索,我认为我无法导入mypackage.R因为r.java我的style.xml文件中的错误而未生成.我一直在寻找如何解决这些问题,但我找不到一个有效的修复方法.错误styles.xml是
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这一问题?
![style.txt中的错误] [1]
这是我正在使用的代码:
package com.example.test;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
更新:这是styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from …Run Code Online (Sandbox Code Playgroud) xml android android-appcompat r.java-file android-support-library
我试图在我的应用程序中发生某些事情时启用/禁用刷新按钮,但是我得到一个我无法弄清楚的空指针异常.我根据情况设置布尔值addingRefresh或removingRefresh为true,然后调用invalidateOptionsMenu()启用或禁用按钮,但菜单项返回null.我在互联网上搜索了为什么会这样但却找不到任何东西.
代码onCreateOptionsMenu()(调用invalidateOptionsMenu()时调用)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (addingRefresh) {
//below line as well as other similar line cause exceptions
menu.findItem(R.id.action_refresh).setEnabled(true);
addingRefresh = false;
} else if (removingRefresh) {
menu.findItem(R.id.action_refresh).setEnabled(false);
removingRefresh = false;
} else if (addingLoading) {
}
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我收到了错误
The entity name must immediately follow the '&' in the entity reference.
Run Code Online (Sandbox Code Playgroud)
但我的XML文档中没有任何&符号!有谁知道为什么会这样?这是我试图解析的XML文档:
<rss version= "2.0" >
<channel>
<item>
<title>Best iPad strategy games</title>
<link>http://feedproxy.google.com/~r/TheIphoneBlog/~3/198mhX3FVmw/story01.htm</link> </item>
<item>
<title>Share your life with friends in real time with Spin</title>
<link>http://feedproxy.google.com/~r/TheIphoneBlog/~3/9G84sETG_9I/story01.htm</link> </item>
<item>
<title>How to stop receiving notifications from a website in OS X Mavericks</title>
<link>http://feedproxy.google.com/~r/TheIphoneBlog/~3/IyxFbLcmoOE/story01.htm</link> </item>
<item>
<title>iPad mini with Retina Display hitting resellers in the UK, 4G LTE models still look scarce</title>
<link>http://feedproxy.google.com/~r/TheIphoneBlog/~3/FGTUITMMR0E/story01.htm</link> </item>
<item>
<title>Procraster for iPhone helps you fight …Run Code Online (Sandbox Code Playgroud) 我有一个onTouchListenerfor 我LinearLayout的ListViews 并且我正在尝试使用ACTION_DOWN和ACTION_UP数据来检测用户何时滑动到下一个ListView. 然而,MotionEventnever equals ACTION_DOWN,虽然ACTION_UP工作完美。经过大量的谷歌搜索,我能找到的唯一解决方案是在调用事件时返回 true,但我已经这样做了。这是我的onTouchListener代码
View.OnTouchListener mTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
downX = event.getX();
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
upX = event.getX();
if(userSwipedFarEnough)
doStuff()
return true;
}
return false;
}
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的Java程序获取一个随机数,但没有任何反应,当我运行程序时,我得到一个java.lang.NullPointerException ...这是我得到random int的代码部分,我将提供之后的完整代码.在此先感谢任何帮助!
try {
PrintStream oFile = new PrintStream("Cipher.txt");
//i get the random number right below here...
rot = random.nextInt(5) + 1;
scan = new Scanner(message);
while (scan.hasNext()) {
cipherWord = scan.next();
l = cipherWord.length();
charScan = new Scanner(cipherWord);
for(int i = 0; i < cipherWord.length(); i++){
cipherChar = cipherWord.charAt(i);
if (cipherChar == 'a') {
cipherChar = 'b';
} else if (cipherChar == 'b') {
cipherChar = 'c';
} else if (cipherChar == 'c') {
cipherChar = 'd';
} …Run Code Online (Sandbox Code Playgroud)